diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-09-20 18:51:08 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-09-20 18:51:43 -0700 |
| commit | 1c9ac9dbb71b778ea99f1c15ad2b02e7f5d2e8fc (patch) | |
| tree | 1b9a298158a1dc3851956e921a2093830c21aace /test/behavior/struct.zig | |
| parent | 500afbf0760d5de7598a4988d1a4b08c21b2dc29 (diff) | |
| download | zig-1c9ac9dbb71b778ea99f1c15ad2b02e7f5d2e8fc.tar.gz zig-1c9ac9dbb71b778ea99f1c15ad2b02e7f5d2e8fc.zip | |
add behavior test: avoid unused field function body compile error
Diffstat (limited to 'test/behavior/struct.zig')
| -rw-r--r-- | test/behavior/struct.zig | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 1f6d951f6d..03a49b70d1 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -2153,3 +2153,26 @@ test "align 1 struct parameter dereferenced and returned" { .little => try expect(s.a == 0x05040302), } } + +test "avoid unused field function body compile error" { + const Case = struct { + const This = @This(); + + const S = struct { + a: usize = 1, + b: fn () void = This.functionThatDoesNotCompile, + }; + + const s: S = .{}; + + fn entry() usize { + return s.a; + } + + pub fn functionThatDoesNotCompile() void { + @compileError("told you so"); + } + }; + + try expect(Case.entry() == 1); +} |
