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! // _ = 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)); env.problems.push(Problem::StmtAfterExpr(stmt_expr.region));
return ValueDef::StmtAfterExpr; return ValueDef::StmtAfterExpr;
@ -229,7 +231,7 @@ fn desugar_value_def<'a>(
)), )),
lines_between: &[], lines_between: &[],
body_pattern: new_pat, 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 { pub fn is_expr_suffixed(expr: &Expr) -> bool {
match expr { match expr {
// expression without arguments, `read!` // expression without arguments, `read!`
Expr::Var { Expr::Var { .. } => false,
module_name: _,
ident,
} => ident.ends_with('!'),
Expr::TrySuffix { .. } => true, Expr::TrySuffix { .. } => true,

View file

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