diff --git a/releasenotes.md b/releasenotes.md index c5152fc19..b1326375b 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -5,7 +5,8 @@ ### Fixes - Assert triggered when casting from `int[2]` to `uint[2]` #2115 - Assert when a macro with compile time value is discarded, e.g. `foo();` where `foo()` returns an untyped list. #2117 - +- Fix stringify for compound initializers #2120. + ### Stdlib changes - Added `String.quick_ztr` and `String.is_zstr` - std::ascii moved into std::core::ascii. Old _m variants are deprecated, as is uint methods. diff --git a/src/compiler/parse_expr.c b/src/compiler/parse_expr.c index d8ce055d3..79b60a854 100644 --- a/src/compiler/parse_expr.c +++ b/src/compiler/parse_expr.c @@ -796,9 +796,9 @@ static Expr *parse_ternary_expr(ParseContext *c, Expr *left_side) static Expr *parse_grouping_expr(ParseContext *c, Expr *left) { ASSERT(!left && "Unexpected left hand side"); - Expr *expr; + SourceSpan span = c->span; advance_and_verify(c, TOKEN_LPAREN); - ASSIGN_EXPR_OR_RET(expr, parse_expr(c), poisoned_expr); + ASSIGN_EXPR_OR_RET(Expr *expr, parse_expr(c), poisoned_expr); CONSUME_OR_RET(TOKEN_RPAREN, poisoned_expr); // Look at what follows. switch (expr->expr_kind) @@ -808,14 +808,15 @@ static Expr *parse_grouping_expr(ParseContext *c, Expr *left) TypeInfo *info = expr->type_expr; if (tok_is(c, TOKEN_LBRACE)) { - return parse_type_compound_literal_expr_after_type(c, info); + ASSIGN_EXPR_OR_RET(expr, parse_type_compound_literal_expr_after_type(c, info), poisoned_expr); + expr->span = extend_span_with_token(span, expr->span); + return expr; } // Create a cast expr if (rules[c->tok].prefix) { Precedence prec = tok_is(c, TOKEN_LBRACE) ? PREC_PRIMARY : PREC_CALL; ASSIGN_EXPRID_OR_RET(ExprId inner, parse_precedence(c, prec), poisoned_expr); - SourceSpan span = expr->span; *expr = (Expr) {.expr_kind = EXPR_CAST, .span = span, .cast_expr.type_info = type_infoid(info), @@ -832,7 +833,6 @@ static Expr *parse_grouping_expr(ParseContext *c, Expr *left) default: break; } - RANGE_EXTEND_PREV(expr); return expr; } diff --git a/test/test_suite/compile_time/stringify_2120.c3t b/test/test_suite/compile_time/stringify_2120.c3t new file mode 100644 index 000000000..a7df5a363 --- /dev/null +++ b/test/test_suite/compile_time/stringify_2120.c3t @@ -0,0 +1,15 @@ +// #target: macos-x64 + +module test; +macro String @echoo(#arg1) +{ + return $stringify(#arg1); +} +fn void main() +{ + String s = @echoo((int[]) { 1, 2 }); +} + +/* #expect: test.ll + +@.str = private unnamed_addr constant [17 x i8] c"(int[]) { 1, 2 }\00", align 1