mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-31 17:17:26 +00:00
Fix PNC + ? suffix interaction
This commit is contained in:
parent
36aa6f0883
commit
1aff18d47c
2 changed files with 46 additions and 31 deletions
|
@ -93,6 +93,29 @@ fn new_op_call_expr<'a>(
|
|||
),
|
||||
);
|
||||
}
|
||||
TrySuffix(PncApply(loc_fn_expr, loc_args)) => {
|
||||
let function = desugar_expr(env, scope, loc_fn_expr);
|
||||
|
||||
let mut desugared_args = Vec::with_capacity_in(loc_args.len(), env.arena);
|
||||
desugared_args.push(desugar_expr(env, scope, left));
|
||||
for loc_arg in loc_args.iter() {
|
||||
desugared_args.push(desugar_expr(env, scope, loc_arg));
|
||||
}
|
||||
|
||||
return Loc::at(
|
||||
region,
|
||||
LowLevelTry(
|
||||
env.arena.alloc(Loc::at(
|
||||
region,
|
||||
Expr::PncApply(
|
||||
function,
|
||||
Collection::with_items(desugared_args.into_bump_slice()),
|
||||
),
|
||||
)),
|
||||
ResultTryKind::OperatorSuffix,
|
||||
),
|
||||
);
|
||||
}
|
||||
TrySuffix(fn_expr) => {
|
||||
let loc_fn = env.arena.alloc(Loc::at(right.region, **fn_expr));
|
||||
let function = desugar_expr(env, scope, loc_fn);
|
||||
|
@ -112,37 +135,6 @@ fn new_op_call_expr<'a>(
|
|||
),
|
||||
);
|
||||
}
|
||||
PncApply(
|
||||
&Loc {
|
||||
value: TrySuffix(fn_expr),
|
||||
region: fn_region,
|
||||
},
|
||||
loc_args,
|
||||
) => {
|
||||
let loc_fn = env.arena.alloc(Loc::at(fn_region, *fn_expr));
|
||||
let function = desugar_expr(env, scope, loc_fn);
|
||||
|
||||
let mut desugared_args = Vec::with_capacity_in(loc_args.len() + 1, env.arena);
|
||||
desugared_args.push(desugar_expr(env, scope, left));
|
||||
for loc_arg in loc_args.items {
|
||||
desugared_args.push(desugar_expr(env, scope, loc_arg));
|
||||
}
|
||||
|
||||
return Loc::at(
|
||||
region,
|
||||
LowLevelTry(
|
||||
env.arena.alloc(Loc::at(
|
||||
region,
|
||||
Expr::Apply(
|
||||
function,
|
||||
desugared_args.into_bump_slice(),
|
||||
CalledVia::Try,
|
||||
),
|
||||
)),
|
||||
ResultTryKind::OperatorSuffix,
|
||||
),
|
||||
);
|
||||
}
|
||||
Apply(
|
||||
&Loc {
|
||||
value: TrySuffix(fn_expr),
|
||||
|
|
|
@ -971,6 +971,29 @@ mod test_can {
|
|||
assert_str_value(&cond_args[0].1.value, "123");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_desugar_pipe_suffix_pnc() {
|
||||
let src = indoc!(
|
||||
r#"
|
||||
"123" |> Str.to_u64()?
|
||||
"#
|
||||
);
|
||||
let arena = Bump::new();
|
||||
let out = can_expr_with(&arena, test_home(), src);
|
||||
|
||||
assert_eq!(out.problems, Vec::new());
|
||||
|
||||
// Assert that we desugar to:
|
||||
//
|
||||
// Try(Str.to_u64 "123")
|
||||
|
||||
let cond_expr = assert_try_expr(&out.loc_expr.value);
|
||||
let cond_args = assert_func_call(cond_expr, "to_u64", CalledVia::Space, &out.interns);
|
||||
|
||||
assert_eq!(cond_args.len(), 1);
|
||||
assert_str_value(&cond_args[0].1.value, "123");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_desugar_works_elsewhere() {
|
||||
let src = indoc!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue