diff options
| author | gingerBill <bill@gingerbill.org> | 2023-08-15 14:55:02 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-08-15 14:55:02 +0100 |
| commit | 2cc22d118d87dfcebce0051c1fb6a4cfad5cb851 (patch) | |
| tree | f9397cb099e3e80f40ebbddc6f6342f333d68904 /src/parser.cpp | |
| parent | 098d1d2b5e46dc792a56776d01b755aff7473822 (diff) | |
Require parentheses for `#align(N)`
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index dd75399ad..13e5f6130 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2485,6 +2485,13 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) { syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string)); } align = parse_expr(f, true); + if (align && align->kind != Ast_ParenExpr) { + ERROR_BLOCK(); + gbString s = expr_to_string(align); + syntax_warning(tag, "#align requires parentheses around the expression"); + error_line("\tSuggestion: #align(%s)", s); + gb_string_free(s); + } } else if (tag.string == "raw_union") { if (is_raw_union) { syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string)); @@ -2566,6 +2573,13 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) { syntax_error(tag, "Duplicate union tag '#%.*s'", LIT(tag.string)); } align = parse_expr(f, true); + if (align && align->kind != Ast_ParenExpr) { + ERROR_BLOCK(); + gbString s = expr_to_string(align); + syntax_warning(tag, "#align requires parentheses around the expression"); + error_line("\tSuggestion: #align(%s)", s); + gb_string_free(s); + } } else if (tag.string == "no_nil") { if (no_nil) { syntax_error(tag, "Duplicate union tag '#%.*s'", LIT(tag.string)); |