diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2023-09-16 22:35:42 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2023-09-17 12:41:11 +0100 |
| commit | 28caaea0938e938de96cc66a49f670005a2df9d4 (patch) | |
| tree | 7e2975d48dd85296bc79d6918d6520c689ebc268 /test/behavior | |
| parent | f40f81cbfb0a867b32d4406e198550730de268cd (diff) | |
| download | zig-28caaea0938e938de96cc66a49f670005a2df9d4.tar.gz zig-28caaea0938e938de96cc66a49f670005a2df9d4.zip | |
AstGen: allow closure over known-runtime values within @TypeOf
AstGen emits an error when a closure over a known-runtime value crosses
a namespace boundary. This usually makes sense: however, this usage is
actually valid if the capture is within a `@TypeOf` operand. Sema
already has a special case to allow such closure within `@TypeOf` when
AstGen could not determine a value to be runtime-known. This commit
simply introduces analagous logic to AstGen to allow `var`s to cross
namespace boundaries within `@TypeOf`.
Diffstat (limited to 'test/behavior')
| -rw-r--r-- | test/behavior/eval.zig | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig index 35cfab9211..aae5c33635 100644 --- a/test/behavior/eval.zig +++ b/test/behavior/eval.zig @@ -991,6 +991,16 @@ test "closure capture type of runtime-known parameter" { try S.b(c); } +test "closure capture type of runtime-known var" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO + + var x: u32 = 1234; + const S = struct { val: @TypeOf(x + 100) }; + const s: S = .{ .val = x }; + try expect(s.val == 1234); +} + test "comptime break passing through runtime condition converted to runtime break" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; |
