Skip to content

Commit

Permalink
Fix desugar step for pizza operator
Browse files Browse the repository at this point in the history
  • Loading branch information
kdziamura committed Jun 22, 2023
1 parent a9f7961 commit b81ceb2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/compiler/can/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,20 +609,27 @@ fn desugar_bin_ops<'a>(
let mut op_stack: Vec<Loc<BinOp>> = Vec::with_capacity_in(lefts.len(), arena);

for (loc_expr, loc_op) in lefts {
arg_stack.push(desugar_expr(arena, loc_expr));
arg_stack.push(desugar_expr_keep_parens(arena, loc_expr));
match run_binop_step(arena, whole_region, &mut arg_stack, &mut op_stack, *loc_op) {
Err(problem) => return problem,
Ok(()) => continue,
}
}

let mut expr = desugar_expr(arena, right);
let mut expr = desugar_expr_keep_parens(arena, right);

for (left, loc_op) in arg_stack.into_iter().zip(op_stack.into_iter()).rev() {
expr = arena.alloc(new_op_call_expr(arena, left, loc_op, expr));
}

expr
desugar_expr(arena, expr)
}

fn desugar_expr_keep_parens<'a>(arena: &'a Bump, expr: &'a Loc<Expr<'a>>) -> &'a Loc<Expr<'a>> {
match expr.value {
ParensAround(_) => expr,
_ => desugar_expr(arena, expr),
}
}

enum Step<'a> {
Expand Down
40 changes: 40 additions & 0 deletions crates/reporting/tests/test_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13841,4 +13841,44 @@ In roc, functions are always written as a lambda, like{}
Tip: It looks like it takes too many arguments. I'm seeing 1 extra.
"###
);

test_report!(
pizza_parens_right,
indoc!(
r#"
2 |> (Num.sub 3)
"#
),
@r###"
── TOO FEW ARGS ────────────────────────────────────────── /code/proj/Main.roc ─
The `sub` function expects 2 arguments, but it got only 1:
4│ 2 |> (Num.sub 3)
^^^^^^^
Roc does not allow functions to be partially applied. Use a closure to
make partial application explicit.
"###
);

test_report!(
pizza_parens_middle,
indoc!(
r#"
2 |> (Num.sub 3) |> Num.sub 3
"#
),
@r###"
── TOO FEW ARGS ────────────────────────────────────────── /code/proj/Main.roc ─
The `sub` function expects 2 arguments, but it got only 1:
4│ 2 |> (Num.sub 3) |> Num.sub 3
^^^^^^^
Roc does not allow functions to be partially applied. Use a closure to
make partial application explicit.
"###
);
}

0 comments on commit b81ceb2

Please sign in to comment.