diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-12-28 15:10:12 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-12-29 12:42:44 +0200 |
| commit | 9a0c593a547eec03a527afaac13fcf11f799c20f (patch) | |
| tree | b0b111e8f3d4c21c49a6d634102b85a9ae9934a7 /test/behavior/eval.zig | |
| parent | 7350f0d9b5aecaf98998bc6591a649d9a7b7091f (diff) | |
| download | zig-9a0c593a547eec03a527afaac13fcf11f799c20f.tar.gz zig-9a0c593a547eec03a527afaac13fcf11f799c20f.zip | |
add tests for fixed stage1 bugs
Closes #1957
Closes #1994
Closes #2140
Closes #2746
Closes #2802
Closes #2855
Closes #2895
Closes #2981
Closes #3054
Closes #3158
Closes #3234
Closes #3259
Closes #3371
Closes #3376
Closes #3387
Closes #3529
Closes #3653
Closes #3750
Closes #3778
Closes #3882
Closes #3915
Closes #3929
Closes #3961
Closes #3988
Closes #4123
Closes #7448
Diffstat (limited to 'test/behavior/eval.zig')
| -rw-r--r-- | test/behavior/eval.zig | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/test/behavior/eval.zig b/test/behavior/eval.zig index 8c3962e3e4..86409c0231 100644 --- a/test/behavior/eval.zig +++ b/test/behavior/eval.zig @@ -1547,3 +1547,77 @@ test "comptime function turns function value to function pointer" { }; comptime try expect(S.foo[0] == &S.Nil); } + +test "container level const and var have unique addresses" { + const S = struct { + x: i32, + y: i32, + const c = @This(){ .x = 1, .y = 1 }; + var v: @This() = c; + }; + var p = &S.c; + try std.testing.expect(p.x == S.c.x); + S.v.x = 2; + try std.testing.expect(p.x == S.c.x); +} + +test "break from block results in type" { + const S = struct { + fn NewType(comptime T: type) type { + const Padded = blk: { + if (@sizeOf(T) <= @sizeOf(usize)) break :blk void; + break :blk T; + }; + + return Padded; + } + }; + const T = S.NewType(usize); + try expect(T == void); +} + +test "struct in comptime false branch is not evaluated" { + const S = struct { + const comptime_const = 2; + fn some(comptime V: type) type { + return switch (comptime_const) { + 3 => struct { a: V.foo }, + 2 => V, + else => unreachable, + }; + } + }; + try expect(S.some(u32) == u32); +} + +test "result of nested switch assigned to variable" { + var zds: u32 = 0; + zds = switch (zds) { + 0 => switch (zds) { + 0...0 => 1234, + 1...1 => zds, + 2 => zds, + else => return, + }, + else => zds, + }; + try expect(zds == 1234); +} + +test "inline for loop of functions returning error unions" { + const T1 = struct { + fn v() error{}!usize { + return 1; + } + }; + const T2 = struct { + fn v() error{Error}!usize { + return 2; + } + }; + var a: usize = 0; + inline for (.{ T1, T2 }) |T| { + a += try T.v(); + } + try expect(a == 3); +} |
