From 5259d11e3b75b9b910fa1b0a479aedb702e256f6 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Sat, 21 Jan 2023 23:12:12 +0200 Subject: [PATCH] Sema: resolve fields before checking tuple len Closes #14400 --- src/Sema.zig | 1 + test/behavior/struct.zig | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/Sema.zig b/src/Sema.zig index a0a071c572..8dc30ebbe5 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -3948,6 +3948,7 @@ fn validateArrayInitTy( return; }, .Struct => if (ty.isTuple()) { + _ = try sema.resolveTypeFields(ty); const array_len = ty.arrayLen(); if (extra.init_count > array_len) { return sema.fail(block, src, "expected at most {d} tuple fields; found {d}", .{ diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index a32a0ed495..ed3e1ce88f 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -1573,3 +1573,8 @@ test "struct fields get automatically reordered" { }; try expect(@sizeOf(S1) == @sizeOf(S2)); } + +test "directly initiating tuple like struct" { + const a = struct { u8 }{8}; + try expect(a[0] == 8); +}