Desugar stmt expr before checking whether it's suffixed

This commit is contained in:
Agus Zubiaga 2024-10-14 23:01:26 -03:00
parent 01c94050c8
commit 460fa693fd
No known key found for this signature in database
3 changed files with 12 additions and 6 deletions

View file

@ -207,7 +207,9 @@ fn desugar_value_def<'a>(
// _ : {}
// _ = stmt_expr!
if env.fx_mode == FxMode::Task && !is_expr_suffixed(&stmt_expr.value) {
let desugared_expr = desugar_expr(env, scope, stmt_expr);
if env.fx_mode == FxMode::Task && !is_expr_suffixed(&desugared_expr.value) {
env.problems.push(Problem::StmtAfterExpr(stmt_expr.region));
return ValueDef::StmtAfterExpr;
@ -229,7 +231,7 @@ fn desugar_value_def<'a>(
)),
lines_between: &[],
body_pattern: new_pat,
body_expr: desugar_expr(env, scope, stmt_expr),
body_expr: desugared_expr,
}
}
}

View file

@ -592,10 +592,7 @@ pub fn is_top_level_suffixed(expr: &Expr) -> bool {
pub fn is_expr_suffixed(expr: &Expr) -> bool {
match expr {
// expression without arguments, `read!`
Expr::Var {
module_name: _,
ident,
} => ident.ends_with('!'),
Expr::Var { .. } => false,
Expr::TrySuffix { .. } => true,

View file

@ -5,5 +5,12 @@ import pf.Effect
main : {} => {}
main = \{} ->
line = Effect.getLine! {}
if line == "secret" then
Effect.putLine! "You found the secret"
Effect.putLine! "Congratulations!"
else
{}
Effect.putLine! "You entered: $(line)"
Effect.putLine! "It is known"