From 543ca97a1ca08cd1080fde67b75aa202ba6c0325 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Sun, 20 Feb 2022 20:17:29 -0500 Subject: [PATCH] Remove spaces around var in record update Closes #2534 --- compiler/can/src/operator.rs | 7 +++++-- compiler/can/tests/test_can.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/compiler/can/src/operator.rs b/compiler/can/src/operator.rs index 04255f9175..6bf103b4c3 100644 --- a/compiler/can/src/operator.rs +++ b/compiler/can/src/operator.rs @@ -170,7 +170,10 @@ pub fn desugar_expr<'a>(arena: &'a Bump, loc_expr: &'a Loc>) -> &'a Loc }), RecordUpdate { fields, update } => { - // NOTE the `update` field is always a `Var { .. }` and does not need to be desugared + // NOTE the `update` field is always a `Var { .. }`, we only desugar it to get rid of + // any spaces before/after + let new_update = desugar_expr(arena, update); + let new_fields = fields.map_items(arena, |field| { let value = desugar_field(arena, &field.value); Loc { @@ -182,7 +185,7 @@ pub fn desugar_expr<'a>(arena: &'a Bump, loc_expr: &'a Loc>) -> &'a Loc arena.alloc(Loc { region: loc_expr.region, value: RecordUpdate { - update: *update, + update: new_update, fields: new_fields, }, }) diff --git a/compiler/can/tests/test_can.rs b/compiler/can/tests/test_can.rs index 3489b0677f..a3ee85d6db 100644 --- a/compiler/can/tests/test_can.rs +++ b/compiler/can/tests/test_can.rs @@ -1063,6 +1063,22 @@ mod test_can { assert_eq!(problems, Vec::new()); } + #[test] + fn issue_2534() { + let src = indoc!( + r#" + x = { a: 1 } + { + x & a: 2 + } + "# + ); + let arena = Bump::new(); + let CanExprOut { problems, .. } = can_expr_with(&arena, test_home(), src); + + assert_eq!(problems, Vec::new()); + } + //#[test] //fn closing_over_locals() { // // "local" should be used, because the closure used it.