Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit a8bd558

Browse files
theofabilousVexu
andcommitted
ast: don't add semicolons to static assertion blocks
Co-authored-by: Veikka Tuominen <[email protected]>
1 parent fd35046 commit a8bd558

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/ast.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@ fn renderNullSentinelArrayType(c: *Context, len: u64, elem_type: Node) !NodeInde
24242424
fn addSemicolonIfNeeded(c: *Context, node: Node) !void {
24252425
switch (node.tag()) {
24262426
.warning => unreachable,
2427-
.var_decl, .var_simple, .arg_redecl, .alias, .block, .empty_block, .block_single, .@"switch", .wrapped_local, .mut_str => {},
2427+
.static_assert, .var_decl, .var_simple, .arg_redecl, .alias, .block, .empty_block, .block_single, .@"switch", .wrapped_local, .mut_str => {},
24282428
.while_true => {
24292429
const payload = node.castTag(.while_true).?.data;
24302430
return addSemicolonIfNotBlock(c, payload);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
_Static_assert(1 == 1, "");
22

3+
void my_function() {
4+
_Static_assert(2 + 2 * 2 == 6, "Math is hard");
5+
}
6+
37
// translate
48
//
59
// comptime {
610
// if (!(@as(c_int, 1) == @as(c_int, 1))) @compileError("static assertion failed \"\"");
711
// }
12+
// pub export fn my_function() void {
13+
// comptime {
14+
// if (!((@as(c_int, 2) + (@as(c_int, 2) * @as(c_int, 2))) == @as(c_int, 6))) @compileError("static assertion failed \"Math is hard\"");
15+
// }
16+
// }

test/cases/translate/unsupport_declare_statement_at_the_last_of_a_compound_statement_which_belongs_to_a_statement_expr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ void somefunc(void) {
1212
// y = 1;
1313
// comptime {
1414
// if (!(@as(c_int, 1) != 0)) @compileError("static assertion failed");
15-
// };
15+
// }
1616
// }
1717
// }

0 commit comments

Comments
 (0)