authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-20 18:51:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-09-20 18:51:43-07:00
log1c9ac9dbb71b778ea99f1c15ad2b02e7f5d2e8fc
tree1b9a298158a1dc3851956e921a2093830c21aace
parent500afbf0760d5de7598a4988d1a4b08c21b2dc29

add behavior test: avoid unused field function body compile error


1 files changed, 23 insertions(+), 0 deletions(-)

test/behavior/struct.zig+23
...@@ -2153,3 +2153,26 @@ test "align 1 struct parameter dereferenced and returned" {...@@ -2153,3 +2153,26 @@ test "align 1 struct parameter dereferenced and returned" {
2153 .little => try expect(s.a == 0x05040302),2153 .little => try expect(s.a == 0x05040302),
2154 }2154 }
2155}2155}
2156
2157test "avoid unused field function body compile error" {
2158 const Case = struct {
2159 const This = @This();
2160
2161 const S = struct {
2162 a: usize = 1,
2163 b: fn () void = This.functionThatDoesNotCompile,
2164 };
2165
2166 const s: S = .{};
2167
2168 fn entry() usize {
2169 return s.a;
2170 }
2171
2172 pub fn functionThatDoesNotCompile() void {
2173 @compileError("told you so");
2174 }
2175 };
2176
2177 try expect(Case.entry() == 1);
2178}