From 1f55355ee0eb20515004f33b3fe6dfc0cd68bb29 Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 20 Jul 2020 13:28:20 +0200 Subject: [PATCH] constrain the default --- compiler/constrain/src/pattern.rs | 4 +++- compiler/solve/tests/solve_expr.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/compiler/constrain/src/pattern.rs b/compiler/constrain/src/pattern.rs index 25db18453a..9af7ebc0ae 100644 --- a/compiler/constrain/src/pattern.rs +++ b/compiler/constrain/src/pattern.rs @@ -246,7 +246,9 @@ pub fn constrain_pattern( state.vars.push(*expr_var); - constrain_expr(env, loc_expr.region, &loc_expr.value, expr_expected); + let expr_con = + constrain_expr(env, loc_expr.region, &loc_expr.value, expr_expected); + state.constraints.push(expr_con); RecordField::Optional(pat_type) } diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index fe3d9be14f..db4d27b26f 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -2641,4 +2641,32 @@ mod solve_expr { "{ x : Num a, y ? Num a }* -> Num a", ); } + + #[test] + fn optional_field_let() { + infer_eq_without_problem( + indoc!( + r#" + { x, y ? 0 } = { x: 32 } + + x + y + "# + ), + "Num *", + ); + } + + #[test] + fn optional_field_when() { + infer_eq_without_problem( + indoc!( + r#" + \r -> + when r is + { x, y ? 0 } -> x + y + "# + ), + "{ x : Num a, y ? Num a }* -> Num a", + ); + } }