diff --git a/compiler/parse/src/ast.rs b/compiler/parse/src/ast.rs index 68c94b8217..9106623060 100644 --- a/compiler/parse/src/ast.rs +++ b/compiler/parse/src/ast.rs @@ -791,6 +791,10 @@ impl<'a> Expr<'a> { value: self, } } + + pub fn is_tag(&self) -> bool { + matches!(self, Expr::GlobalTag(_) | Expr::PrivateTag(_)) + } } macro_rules! impl_extract_spaces { diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index 5b5e19c352..6e34e6fd0d 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -410,7 +410,7 @@ impl<'a> ExprState<'a> { let fail = EExpr::BadOperator(opchar, loc_op.region.start()); Err(fail) - } else if !self.arguments.is_empty() { + } else if !self.expr.value.is_tag() && !self.arguments.is_empty() { let region = Region::across_all(self.arguments.iter().map(|v| &v.region)); Err(argument_error(region, loc_op.region.start())) diff --git a/compiler/parse/tests/snapshots/pass/destructure_tag_assignment.expr.result-ast b/compiler/parse/tests/snapshots/pass/destructure_tag_assignment.expr.result-ast new file mode 100644 index 0000000000..58acb2a0fd --- /dev/null +++ b/compiler/parse/tests/snapshots/pass/destructure_tag_assignment.expr.result-ast @@ -0,0 +1,38 @@ +Defs( + [ + |L 0-0, C 0-36| Body( + |L 0-0, C 0-5| Apply( + |L 0-0, C 0-5| GlobalTag( + "Email", + ), + [ + |L 0-0, C 6-9| Identifier( + "str", + ), + ], + ), + |L 0-0, C 12-36| Apply( + |L 0-0, C 12-17| GlobalTag( + "Email", + ), + [ + |L 0-0, C 18-36| Str( + PlainLine( + "blah@example.com", + ), + ), + ], + Space, + ), + ), + ], + |L 1-1, C 0-3| SpaceBefore( + Var { + module_name: "", + ident: "str", + }, + [ + Newline, + ], + ), +) diff --git a/compiler/parse/tests/snapshots/pass/destructure_tag_assignment.expr.roc b/compiler/parse/tests/snapshots/pass/destructure_tag_assignment.expr.roc new file mode 100644 index 0000000000..e97a842431 --- /dev/null +++ b/compiler/parse/tests/snapshots/pass/destructure_tag_assignment.expr.roc @@ -0,0 +1,2 @@ +Email str = Email "blah@example.com" +str diff --git a/compiler/parse/tests/test_parse.rs b/compiler/parse/tests/test_parse.rs index 3dc061201e..e780e29e26 100644 --- a/compiler/parse/tests/test_parse.rs +++ b/compiler/parse/tests/test_parse.rs @@ -130,6 +130,7 @@ mod test_parse { pass/comment_before_op.expr, pass/comment_inside_empty_list.expr, pass/comment_with_non_ascii.expr, + pass/destructure_tag_assignment.expr, pass/empty_app_header.header, pass/empty_interface_header.header, pass/empty_list.expr,