diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2023-11-08 19:32:32 +0000 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-11-08 23:47:10 -0700 |
| commit | 997eaf6d8724fe2076195de4d6d54bf2bf880eea (patch) | |
| tree | d423bc12df1141b2f8029f7a88e4f0f56413a316 /test/behavior/struct.zig | |
| parent | f258a391daa31b3ba2c37d879db96fadc0c058f3 (diff) | |
| download | zig-997eaf6d8724fe2076195de4d6d54bf2bf880eea.tar.gz zig-997eaf6d8724fe2076195de4d6d54bf2bf880eea.zip | |
Sema: do not force resolution of struct field inits when calling function pointer field
b3462b7 caused a regression in a third-party project, since it forced
resolution of field initializers for any field call 'foo.bar()', despite
this only being necessary when 'bar' is a comptime field.
See https://github.com/ziglang/zig/pull/17692#issuecomment-1802096734.
Diffstat (limited to 'test/behavior/struct.zig')
| -rw-r--r-- | test/behavior/struct.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 7b2587b3d6..08954dfd68 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -1842,3 +1842,18 @@ test "circular dependency through pointer field of a struct" { try expect(outer.middle.outer == null); try expect(outer.middle.inner == null); } + +test "field calls do not force struct field init resolution" { + const S = struct { + x: u32 = blk: { + _ = @TypeOf(make().dummyFn()); // runtime field call - S not fully resolved - dummyFn call should not force field init resolution + break :blk 123; + }, + dummyFn: *const fn () void = undefined, + fn make() @This() { + return .{}; + } + }; + var s: S = .{}; + try expect(s.x == 123); +} |
