authorgravatar for fkoppe@web.deFelix Koppe <fkoppe@web.de> 2025-07-18 00:07:50+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-07-17 22:07:50+00:00
log3ae0ba096d6ba9181a984d0745e1e079c67d62ff
tree0ae8b15ae1f5067647efbe499fd55ba19b005e89
parent32c9e5df894752a8fbc3b8c8a6e5fb0cfd5e8f1b
signaturebadge-check Signed by PGP key B5690EEEBB952194

test: Restore and fix deleted tests that relied on intern pool types (#24422)


6 files changed, 265 insertions(+), 20 deletions(-)

test/cases/compile_errors/@import_zon_bad_type.zig created+128
...@@ -0,0 +1,128 @@
1export fn testVoid() void {
2 const f: void = @import("zon/neg_inf.zon");
3 _ = f;
4}
5
6export fn testInStruct() void {
7 const f: struct { f: [*]const u8 } = @import("zon/neg_inf.zon");
8 _ = f;
9}
10
11export fn testError() void {
12 const f: struct { error{foo} } = @import("zon/neg_inf.zon");
13 _ = f;
14}
15
16export fn testInUnion() void {
17 const f: union(enum) { a: void, b: [*c]const u8 } = @import("zon/neg_inf.zon");
18 _ = f;
19}
20
21export fn testInVector() void {
22 const f: @Vector(0, [*c]const u8) = @import("zon/neg_inf.zon");
23 _ = f;
24}
25
26export fn testInOpt() void {
27 const f: *const ?[*c]const u8 = @import("zon/neg_inf.zon");
28 _ = f;
29}
30
31export fn testComptimeField() void {
32 const f: struct { comptime foo: ??u8 = null } = @import("zon/neg_inf.zon");
33 _ = f;
34}
35
36export fn testEnumLiteral() void {
37 const f: @TypeOf(.foo) = @import("zon/neg_inf.zon");
38 _ = f;
39}
40
41export fn testNestedOpt1() void {
42 const f: ??u8 = @import("zon/neg_inf.zon");
43 _ = f;
44}
45
46export fn testNestedOpt2() void {
47 const f: ?*const ?u8 = @import("zon/neg_inf.zon");
48 _ = f;
49}
50
51export fn testNestedOpt3() void {
52 const f: *const ?*const ?*const u8 = @import("zon/neg_inf.zon");
53 _ = f;
54}
55
56export fn testOpt() void {
57 const f: ?u8 = @import("zon/neg_inf.zon");
58 _ = f;
59}
60
61const E = enum(u8) { _ };
62export fn testNonExhaustiveEnum() void {
63 const f: E = @import("zon/neg_inf.zon");
64 _ = f;
65}
66
67const U = union { foo: void };
68export fn testUntaggedUnion() void {
69 const f: U = @import("zon/neg_inf.zon");
70 _ = f;
71}
72
73const EU = union(enum) { foo: void };
74export fn testTaggedUnionVoid() void {
75 const f: EU = @import("zon/neg_inf.zon");
76 _ = f;
77}
78
79export fn testVisited() void {
80 const V = struct {
81 ?f32, // Adds `?f32` to the visited list
82 ??f32, // `?f32` is already visited, we need to detect the nested opt anyway
83 f32,
84 };
85 const f: V = @import("zon/neg_inf.zon");
86 _ = f;
87}
88
89export fn testMutablePointer() void {
90 const f: *i32 = @import("zon/neg_inf.zon");
91 _ = f;
92}
93
94// error
95// imports=zon/neg_inf.zon
96//
97// tmp.zig:2:29: error: type 'void' is not available in ZON
98// tmp.zig:7:50: error: type '[*]const u8' is not available in ZON
99// tmp.zig:7:50: note: ZON does not allow many-pointers
100// tmp.zig:12:46: error: type 'error{foo}' is not available in ZON
101// tmp.zig:17:65: error: type '[*c]const u8' is not available in ZON
102// tmp.zig:17:65: note: ZON does not allow C pointers
103// tmp.zig:22:49: error: type '[*c]const u8' is not available in ZON
104// tmp.zig:22:49: note: ZON does not allow C pointers
105// tmp.zig:27:45: error: type '[*c]const u8' is not available in ZON
106// tmp.zig:27:45: note: ZON does not allow C pointers
107// tmp.zig:32:61: error: type '??u8' is not available in ZON
108// tmp.zig:32:61: note: ZON does not allow nested optionals
109// tmp.zig:42:29: error: type '??u8' is not available in ZON
110// tmp.zig:42:29: note: ZON does not allow nested optionals
111// tmp.zig:47:36: error: type '?*const ?u8' is not available in ZON
112// tmp.zig:47:36: note: ZON does not allow nested optionals
113// tmp.zig:52:50: error: type '?*const ?*const u8' is not available in ZON
114// tmp.zig:52:50: note: ZON does not allow nested optionals
115// tmp.zig:85:26: error: type '??f32' is not available in ZON
116// tmp.zig:85:26: note: ZON does not allow nested optionals
117// tmp.zig:90:29: error: type '*i32' is not available in ZON
118// tmp.zig:90:29: note: ZON does not allow mutable pointers
119// neg_inf.zon:1:1: error: expected type '@Type(.enum_literal)'
120// tmp.zig:37:38: note: imported here
121// neg_inf.zon:1:1: error: expected type '?u8'
122// tmp.zig:57:28: note: imported here
123// neg_inf.zon:1:1: error: expected type 'tmp.E'
124// tmp.zig:63:26: note: imported here
125// neg_inf.zon:1:1: error: expected type 'tmp.U'
126// tmp.zig:69:26: note: imported here
127// neg_inf.zon:1:1: error: expected type 'tmp.EU'
128// tmp.zig:75:27: note: imported here
test/cases/compile_errors/anytype_param_requires_comptime.zig created+21
...@@ -0,0 +1,21 @@
1const C = struct {
2 c: type,
3 b: u32,
4};
5const S = struct {
6 fn foo(b: u32, c: anytype) void {
7 bar(C{ .c = c, .b = b });
8 }
9 fn bar(_: anytype) void {}
10};
11
12pub export fn entry() void {
13 S.foo(0, u32);
14}
15
16// error
17//
18//:7:25: error: unable to resolve comptime value
19//:7:25: note: initializer of comptime-only struct 'tmp.C' must be comptime-known
20//:2:8: note: struct requires comptime because of this field
21//:2:8: note: types are not available at runtime
test/cases/compile_errors/bogus_method_call_on_slice.zig created+26
...@@ -0,0 +1,26 @@
1var self = "aoeu";
2
3fn f(m: []const u8) void {
4 m.copy(u8, self[0..], m);
5}
6
7export fn entry() usize {
8 return @sizeOf(@TypeOf(&f));
9}
10
11pub export fn entry1() void {
12 .{}.bar();
13}
14
15const S = struct { foo: i32 };
16pub export fn entry2() void {
17 const x = S{ .foo = 1 };
18 x.bar();
19}
20
21// error
22//
23// :4:6: error: no field or member function named 'copy' in '[]const u8'
24// :12:8: error: no field or member function named 'bar' in '@TypeOf(.{})'
25// :18:6: error: no field or member function named 'bar' in 'tmp.S'
26// :15:11: note: struct declared here
test/cases/compile_errors/coerce_anon_struct.zig created+12
...@@ -0,0 +1,12 @@
1const A = struct { x: u32 };
2const T = struct { x: u32 };
3export fn foo() void {
4 const a = A{ .x = 123 };
5 _ = @as(T, a);
6}
7
8// error
9//
10// :5:16: error: expected type 'tmp.T', found 'tmp.A'
11// :1:11: note: struct declared here
12// :2:11: note: struct declared here
test/cases/compile_errors/redundant_try.zig created+52
...@@ -0,0 +1,52 @@
1const S = struct { x: u32 = 0 };
2const T = struct { []const u8 };
3
4fn test0() !void {
5 const x: u8 = try 1;
6 _ = x;
7}
8
9fn test1() !void {
10 const x: S = try .{};
11 _ = x;
12}
13
14fn test2() !void {
15 const x: S = try S{ .x = 123 };
16 _ = x;
17}
18
19fn test3() !void {
20 const x: S = try try S{ .x = 123 };
21 _ = x;
22}
23
24fn test4() !void {
25 const x: T = try .{"hello"};
26 _ = x;
27}
28
29fn test5() !void {
30 const x: error{Foo}!u32 = 123;
31 _ = try try x;
32}
33
34comptime {
35 _ = &test0;
36 _ = &test1;
37 _ = &test2;
38 _ = &test3;
39 _ = &test4;
40 _ = &test5;
41}
42
43// error
44//
45// :5:23: error: expected error union type, found 'comptime_int'
46// :10:23: error: expected error union type, found '@TypeOf(.{})'
47// :15:23: error: expected error union type, found 'tmp.S'
48// :1:11: note: struct declared here
49// :20:27: error: expected error union type, found 'tmp.S'
50// :1:11: note: struct declared here
51// :25:23: error: expected error union type, found 'struct { comptime *const [5:0]u8 = "hello" }'
52// :31:13: error: expected error union type, found 'u32'
test/cases/type_names.zig+26-20
...@@ -46,14 +46,18 @@ const StructInStruct = struct { a: struct { b: u8 } };...@@ -46,14 +46,18 @@ const StructInStruct = struct { a: struct { b: u8 } };
46const UnionInStruct = struct { a: union { b: u8 } };46const UnionInStruct = struct { a: union { b: u8 } };
47const StructInUnion = union { a: struct { b: u8 } };47const StructInUnion = union { a: struct { b: u8 } };
48const UnionInUnion = union { a: union { b: u8 } };48const UnionInUnion = union { a: union { b: u8 } };
49const StructInTuple = struct { struct { b: u8 } };49const InnerStruct = struct { b: u8 };
50const UnionInTuple = struct { union { b: u8 } };50const StructInTuple = struct { a: InnerStruct };
51const InnerUnion = union { b: u8 };
52const UnionInTuple = struct { a: InnerUnion };
5153
52export fn nestedTypes() void {54export fn nestedTypes() void {
53 @compileLog(@typeName(StructInStruct));55 @compileLog(@typeName(StructInStruct));
54 @compileLog(@typeName(UnionInStruct));56 @compileLog(@typeName(UnionInStruct));
55 @compileLog(@typeName(StructInUnion));57 @compileLog(@typeName(StructInUnion));
56 @compileLog(@typeName(UnionInUnion));58 @compileLog(@typeName(UnionInUnion));
59 @compileLog(@typeName(StructInTuple));
60 @compileLog(@typeName(UnionInTuple));
57}61}
5862
59// error63// error
...@@ -61,22 +65,24 @@ export fn nestedTypes() void {...@@ -61,22 +65,24 @@ export fn nestedTypes() void {
61// :8:5: error: found compile log statement65// :8:5: error: found compile log statement
62// :19:5: note: also here66// :19:5: note: also here
63// :39:5: note: also here67// :39:5: note: also here
64// :53:5: note: also here68// :55:5: note: also here
65//69//
66// Compile Log Output:70//Compile Log Output:
67// @as(*const [15:0]u8, "tmp.namespace.S")71//@as(*const [15:0]u8, "tmp.namespace.S")
68// @as(*const [15:0]u8, "tmp.namespace.E")72//@as(*const [15:0]u8, "tmp.namespace.E")
69// @as(*const [15:0]u8, "tmp.namespace.U")73//@as(*const [15:0]u8, "tmp.namespace.U")
70// @as(*const [15:0]u8, "tmp.namespace.O")74//@as(*const [15:0]u8, "tmp.namespace.O")
71// @as(*const [19:0]u8, "tmp.localVarValue.S")75//@as(*const [19:0]u8, "tmp.localVarValue.S")
72// @as(*const [19:0]u8, "tmp.localVarValue.E")76//@as(*const [19:0]u8, "tmp.localVarValue.E")
73// @as(*const [19:0]u8, "tmp.localVarValue.U")77//@as(*const [19:0]u8, "tmp.localVarValue.U")
74// @as(*const [19:0]u8, "tmp.localVarValue.O")78//@as(*const [19:0]u8, "tmp.localVarValue.O")
75// @as(*const [11:0]u8, "tmp.MakeS()")79//@as(*const [11:0]u8, "tmp.MakeS()")
76// @as(*const [11:0]u8, "tmp.MakeE()")80//@as(*const [11:0]u8, "tmp.MakeE()")
77// @as(*const [11:0]u8, "tmp.MakeU()")81//@as(*const [11:0]u8, "tmp.MakeU()")
78// @as(*const [11:0]u8, "tmp.MakeO()")82//@as(*const [11:0]u8, "tmp.MakeO()")
79// @as(*const [18:0]u8, "tmp.StructInStruct")83//@as(*const [18:0]u8, "tmp.StructInStruct")
80// @as(*const [17:0]u8, "tmp.UnionInStruct")84//@as(*const [17:0]u8, "tmp.UnionInStruct")
81// @as(*const [17:0]u8, "tmp.StructInUnion")85//@as(*const [17:0]u8, "tmp.StructInUnion")
82// @as(*const [16:0]u8, "tmp.UnionInUnion")86//@as(*const [16:0]u8, "tmp.UnionInUnion")
87//@as(*const [17:0]u8, "tmp.StructInTuple")
88//@as(*const [16:0]u8, "tmp.UnionInTuple")