Fixed statement bodies

This commit is contained in:
2026-05-24 14:43:09 +02:00
parent 63cc20107c
commit f21cd5a927
6 changed files with 20 additions and 29 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ impl GenRust for Expression {
if ensure_semicolon {
ctx.expr_ensure_semicolon = true;
if !self.is_soft_return() {
if !self.is_block() {
cg.add(";");
}
}
+7 -3
View File
@@ -95,10 +95,14 @@ impl RustCodegen {
}
}
pub fn ensure_brackets_body(&mut self, ctx: &mut Context, expr: &StatementBody) {
match expr {
StatementBody::Statement(expr) => self.ensure_brackets_expr(ctx, expr),
pub fn ensure_brackets_body(&mut self, ctx: &mut Context, body: &StatementBody) {
match body {
StatementBody::Expression(expr) => self.ensure_brackets_expr(ctx, expr),
StatementBody::Statement(expr) => {
ctx.expr_ensure_semicolon = true;
self.ensure_brackets_expr(ctx, expr);
}
}
}
}
+1 -1
View File
@@ -31,8 +31,8 @@ impl GenRust for StatementBody {
match self {
Self::Expression(expr) => expr.gen_rust(ctx, cg),
Self::Statement(stmt) => {
ctx.expr_ensure_semicolon = true;
stmt.gen_rust(ctx, cg);
cg.add(";");
}
}
}