diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2023-05-20 23:21:52 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-05-29 11:32:13 -0700 |
| commit | e2837fd2245c213c842617d6d98e311057893bb0 (patch) | |
| tree | e42c8accf30a118fdb63f0c5302dd89d9f905f8d /test/behavior/maximum_minimum.zig | |
| parent | 46e724ab28ba5934471d8b2dec60acdd7885d64b (diff) | |
| download | zig-e2837fd2245c213c842617d6d98e311057893bb0.tar.gz zig-e2837fd2245c213c842617d6d98e311057893bb0.zip | |
Sema: return comptime_int if all args to @min/@max are comptime_int
Resolves: #15776
Diffstat (limited to 'test/behavior/maximum_minimum.zig')
| -rw-r--r-- | test/behavior/maximum_minimum.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/behavior/maximum_minimum.zig b/test/behavior/maximum_minimum.zig index 648d4d9493..2750dbdb6f 100644 --- a/test/behavior/maximum_minimum.zig +++ b/test/behavior/maximum_minimum.zig @@ -194,3 +194,20 @@ test "@min/@max notices vector bounds" { try expectEqual(@Vector(2, u32){ 140, 300 }, max); try expectEqual(@Vector(2, u32), @TypeOf(max)); } + +test "@min/@max on comptime_int" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO + + const min = @min(1, 2, -2, -1); + const max = @max(1, 2, -2, -1); + + try expectEqual(comptime_int, @TypeOf(min)); + try expectEqual(comptime_int, @TypeOf(max)); + try expectEqual(-2, min); + try expectEqual(2, max); +} |
