diff --git a/src/InternPool.zig b/src/InternPool.zig index 60d24223ce..8f99c9d810 100644 --- 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 new file mode 100644 index 0000000000..b514bc10e7 --- /dev/null +++ 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