zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 96d6b22067cccd644190e9b63f8f5bc13b6e93db (tree)
parent 4e92592fee6b414757b2e6c088e20ca9a1b21f44
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date:   Sun,  8 Feb 2026 13:24:03 +0000

tests: update for accepted language change

'comptime_int' is no longer considered a valid backing type for an enum.
In other words, 'enum(comptime_int)' is a compile error. This change is
accepted to simplify the language.

Diffstat:
Mtest/behavior/enum.zig | 16----------------
Mtest/behavior/union.zig | 35++++++++++++-----------------------
Atest/cases/compile_errors/enum_backed_by_comptime_int.zig | 8++++++++
Dtest/cases/compile_errors/enum_backed_by_comptime_int_must_be_casted_from_comptime_value.zig | 12------------
Dtest/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig | 9---------
Atest/cases/compile_errors/union_backed_by_enum_backed_by_comptime_int.zig | 9+++++++++
6 files changed, 29 insertions(+), 60 deletions(-)

diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig @@ -823,15 +823,6 @@ test "enum with one member and u1 tag type @intFromEnum" { try expect(@intFromEnum(Enum.Test) == 0); } -test "enum with comptime_int tag type" { - const Enum = enum(comptime_int) { - One = 3, - Two = 2, - Three = 1, - }; - comptime assert(Tag(Enum) == comptime_int); -} - test "enum with one member default to u0 tag type" { const E0 = enum { X }; comptime assert(Tag(E0) == u0); @@ -1274,13 +1265,6 @@ fn getLazyInitialized(param: enum(u8) { return @intFromEnum(param); } -test "Non-exhaustive enum backed by comptime_int" { - const E = enum(comptime_int) { a, b, c, _ }; - comptime var e: E = .a; - e = @as(E, @enumFromInt(378089457309184723749)); - try expect(@intFromEnum(e) == 378089457309184723749); -} - test "matching captures causes enum equivalence" { const S = struct { fn Nonexhaustive(comptime I: type) type { diff --git a/test/behavior/union.zig b/test/behavior/union.zig @@ -703,25 +703,23 @@ test "union with only 1 field casted to its enum type which has enum value speci if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO const Literal = union(enum) { - Number: f64, - Bool: bool, + number: f64, + bool: bool, }; - const ExprTag = enum(comptime_int) { - Literal = 33, - }; + const ExprTag = enum(u32) { literal = 33 }; + const Expr = union(ExprTag) { literal: Literal }; - const Expr = union(ExprTag) { - Literal: Literal, - }; + comptime assert(Tag(ExprTag) == u32); - var e = Expr{ .Literal = Literal{ .Bool = true } }; - _ = &e; - comptime assert(Tag(ExprTag) == comptime_int); - const t = comptime @as(ExprTag, e); - try expect(t == Expr.Literal); - try expect(@intFromEnum(t) == 33); + var e: Expr = undefined; + e = .{ .literal = .{ .bool = true } }; + + const t: ExprTag = e; + comptime assert(t == Expr.literal); comptime assert(@intFromEnum(t) == 33); + try expect(t == Expr.literal); + try expect(@intFromEnum(t) == 33); } test "@intFromEnum works on unions" { @@ -893,15 +891,6 @@ test "union no tag with struct member" { u.foo(); } -test "union with comptime_int tag" { - const Union = union(enum(comptime_int)) { - X: u32, - Y: u16, - Z: u8, - }; - comptime assert(Tag(Tag(Union)) == comptime_int); -} - test "extern union doesn't trigger field check at comptime" { const U = extern union { x: u32, diff --git a/test/cases/compile_errors/enum_backed_by_comptime_int.zig b/test/cases/compile_errors/enum_backed_by_comptime_int.zig @@ -0,0 +1,8 @@ +const E = enum(comptime_int) { a }; +comptime { + _ = E.a; +} + +// error +// +// :1:16: error: expected integer tag type, found 'comptime_int' diff --git a/test/cases/compile_errors/enum_backed_by_comptime_int_must_be_casted_from_comptime_value.zig b/test/cases/compile_errors/enum_backed_by_comptime_int_must_be_casted_from_comptime_value.zig @@ -1,12 +0,0 @@ -export fn entry() void { - const Tag = enum(comptime_int) { a, b }; - - var v: u32 = 0; - _ = &v; - _ = @as(Tag, @enumFromInt(v)); -} - -// error -// -// :6:31: error: unable to resolve comptime value -// :6:31: note: value casted to enum with 'comptime_int' tag type must be comptime-known 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 @@ -1,9 +0,0 @@ -pub export fn entry() void { - const E = enum(comptime_int) { a, b, c, _ }; - var e: E = .a; - _ = &e; -} - -// error -// -// :3:12: error: variable of type 'tmp.entry.E' must be const or comptime diff --git a/test/cases/compile_errors/union_backed_by_enum_backed_by_comptime_int.zig b/test/cases/compile_errors/union_backed_by_enum_backed_by_comptime_int.zig @@ -0,0 +1,9 @@ +const U = union(enum(comptime_int)) { a: u32 }; +comptime { + const u: U = .{ .a = 123 }; + _ = u; +} + +// error +// +// :1:22: error: expected integer tag type, found 'comptime_int'