Skip to content

Commit

Permalink
Desugar stmt expr before checking whether it's suffixed
Browse files Browse the repository at this point in the history
  • Loading branch information
agu-z committed Oct 15, 2024
1 parent 4c55930 commit 5c5c263
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions crates/compiler/can/src/desugar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,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;
Expand All @@ -182,7 +184,7 @@ fn desugar_value_def<'a>(
)),
lines_between: &[],
body_pattern: new_pat,
body_expr: desugar_expr(env, scope, stmt_expr),
body_expr: desugared_expr,
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions crates/compiler/parse/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,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,

Expand Down
7 changes: 7 additions & 0 deletions examples/cli/effects.roc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 5c5c263

Please sign in to comment.