diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-09-02 16:08:20 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-09-02 17:57:11 +0300 |
| commit | f281f3d10e4eaedc7c68afc4fcbbfd35e1f29a0f (patch) | |
| tree | 3a28628a95126b07fe7fa17e12ff3cbab1e9df65 /test | |
| parent | a9cdacff95a2a6f60945c7b2a299f9f66bd94ddb (diff) | |
| download | zig-f281f3d10e4eaedc7c68afc4fcbbfd35e1f29a0f.tar.gz zig-f281f3d10e4eaedc7c68afc4fcbbfd35e1f29a0f.zip | |
Sema: improve behavior of comptime_int backed enums
Diffstat (limited to 'test')
| -rw-r--r-- | test/behavior/enum.zig | 7 | ||||
| -rw-r--r-- | test/behavior/union.zig | 2 | ||||
| -rw-r--r-- | test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig | 11 |
3 files changed, 19 insertions, 1 deletions
diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig index 517414780b..28c8785e64 100644 --- a/test/behavior/enum.zig +++ b/test/behavior/enum.zig @@ -1175,3 +1175,10 @@ test "Non-exhaustive enum with nonstandard int size behaves correctly" { const E = enum(u15) { _ }; try expect(@sizeOf(E) == @sizeOf(u15)); } + +test "Non-exhaustive enum backed by comptime_int" { + const E = enum(comptime_int) { a, b, c, _ }; + comptime var e: E = .a; + e = @intToEnum(E, 378089457309184723749); + try expect(@enumToInt(e) == 378089457309184723749); +} diff --git a/test/behavior/union.zig b/test/behavior/union.zig index 9053a860a6..b94034adf4 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -690,7 +690,7 @@ test "union with only 1 field casted to its enum type which has enum value speci var e = Expr{ .Literal = Literal{ .Bool = true } }; comptime try expect(Tag(ExprTag) == comptime_int); - var t = @as(ExprTag, e); + comptime var t = @as(ExprTag, e); try expect(t == Expr.Literal); try expect(@enumToInt(t) == 33); comptime try expect(@enumToInt(t) == 33); diff --git a/test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig b/test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig new file mode 100644 index 0000000000..7dab294d4a --- /dev/null +++ b/test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig @@ -0,0 +1,11 @@ +pub export fn entry() void { + const E = enum(comptime_int) { a, b, c, _ }; + var e: E = .a; + _ = e; +} + +// error +// backend=stage2 +// target=native +// +// :3:12: error: variable of type 'tmp.entry.E' must be const or comptime |
