From fda6c708357a8b636d2e1142d6594b1436ee86d5 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Thu, 30 Dec 2021 18:21:28 -0600 Subject: [PATCH] Mark patterns in lambda argument position as having a presence constraint Closes #2299 --- compiler/constrain/src/expr.rs | 2 +- compiler/solve/tests/solve_expr.rs | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/compiler/constrain/src/expr.rs b/compiler/constrain/src/expr.rs index 71c05c8281..0b72c6f1ce 100644 --- a/compiler/constrain/src/expr.rs +++ b/compiler/constrain/src/expr.rs @@ -77,7 +77,7 @@ fn constrain_untyped_args( loc_pattern.region, pattern_expected, &mut pattern_state, - false, + true, ); vars.push(*pattern_var); diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index 6a55b884a9..49c43e9c61 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -1327,7 +1327,7 @@ mod solve_expr { \Foo -> 42 "# ), - "[ Foo ]* -> Num *", + "[ Foo ] -> Num *", ); } @@ -1339,7 +1339,7 @@ mod solve_expr { \@Foo -> 42 "# ), - "[ @Foo ]* -> Num *", + "[ @Foo ] -> Num *", ); } @@ -1419,7 +1419,7 @@ mod solve_expr { \Foo x -> Foo x "# ), - "[ Foo a ]* -> [ Foo a ]*", + "[ Foo a ] -> [ Foo a ]*", ); } @@ -1431,7 +1431,7 @@ mod solve_expr { \Foo x _ -> Foo x "y" "# ), - "[ Foo a * ]* -> [ Foo a Str ]*", + "[ Foo a * ] -> [ Foo a Str ]*", ); } @@ -4909,4 +4909,17 @@ mod solve_expr { "{ x : [ Blue, Red ], y ? Num a }* -> Num a", ) } + + #[test] + // Issue #2299 + fn infer_union_argument_position() { + infer_eq_without_problem( + indoc!( + r#" + \UserId id -> id + 1 + "# + ), + "[ UserId (Num a) ] -> Num a", + ) + } }