zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3ce857d0543780e96bfd50d75d53d870ff308fef (tree)
parent f01f1e33c96f0b00db8e036a654c1b3bf8531cd8
Author: mlugg <mlugg@mlugg.co.uk>
Date:   Wed,  5 Feb 2025 18:31:39 +0000

Sema: fix incorrectly succeeding type resolution

Resolves: #21436

Diffstat:
Msrc/InternPool.zig | 2+-
Atest/cases/compile_errors/struct_depends_on_itself_via_non_initial_field.zig | 12++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/InternPool.zig b/src/InternPool.zig @@ -4011,7 +4011,7 @@ pub const LoadedStructType = struct { pub fn haveFieldTypes(s: LoadedStructType, ip: *const InternPool) bool { const types = s.field_types.get(ip); - return types.len == 0 or types[0] != .none; + return types.len == 0 or types[types.len - 1] != .none; } pub fn haveFieldInits(s: LoadedStructType, ip: *const InternPool) bool { diff --git a/test/cases/compile_errors/struct_depends_on_itself_via_non_initial_field.zig b/test/cases/compile_errors/struct_depends_on_itself_via_non_initial_field.zig @@ -0,0 +1,12 @@ +const A = struct { + a: u8, + bytes: [@sizeOf(A)]u8, +}; + +comptime { + _ = A; +} + +// error +// +// :1:11: error: struct 'tmp.A' depends on itself