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

This commit is contained in:
Felix Koppe 2025-07-18 00:07:50 +02:00 committed by GitHub
parent 32c9e5df89
commit 3ae0ba096d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 265 additions and 20 deletions

View file

@ -0,0 +1,128 @@
export fn testVoid() void {
const f: void = @import("zon/neg_inf.zon");
_ = f;
}
export fn testInStruct() void {
const f: struct { f: [*]const u8 } = @import("zon/neg_inf.zon");
_ = f;
}
export fn testError() void {
const f: struct { error{foo} } = @import("zon/neg_inf.zon");
_ = f;
}
export fn testInUnion() void {
const f: union(enum) { a: void, b: [*c]const u8 } = @import("zon/neg_inf.zon");
_ = f;
}
export fn testInVector() void {
const f: @Vector(0, [*c]const u8) = @import("zon/neg_inf.zon");
_ = f;
}
export fn testInOpt() void {
const f: *const ?[*c]const u8 = @import("zon/neg_inf.zon");
_ = f;
}
export fn testComptimeField() void {
const f: struct { comptime foo: ??u8 = null } = @import("zon/neg_inf.zon");
_ = f;
}
export fn testEnumLiteral() void {
const f: @TypeOf(.foo) = @import("zon/neg_inf.zon");
_ = f;
}
export fn testNestedOpt1() void {
const f: ??u8 = @import("zon/neg_inf.zon");
_ = f;
}
export fn testNestedOpt2() void {
const f: ?*const ?u8 = @import("zon/neg_inf.zon");
_ = f;
}
export fn testNestedOpt3() void {
const f: *const ?*const ?*const u8 = @import("zon/neg_inf.zon");
_ = f;
}
export fn testOpt() void {
const f: ?u8 = @import("zon/neg_inf.zon");
_ = f;
}
const E = enum(u8) { _ };
export fn testNonExhaustiveEnum() void {
const f: E = @import("zon/neg_inf.zon");
_ = f;
}
const U = union { foo: void };
export fn testUntaggedUnion() void {
const f: U = @import("zon/neg_inf.zon");
_ = f;
}
const EU = union(enum) { foo: void };
export fn testTaggedUnionVoid() void {
const f: EU = @import("zon/neg_inf.zon");
_ = f;
}
export fn testVisited() void {
const V = struct {
?f32, // Adds `?f32` to the visited list
??f32, // `?f32` is already visited, we need to detect the nested opt anyway
f32,
};
const f: V = @import("zon/neg_inf.zon");
_ = f;
}
export fn testMutablePointer() void {
const f: *i32 = @import("zon/neg_inf.zon");
_ = f;
}
// error
// imports=zon/neg_inf.zon
//
// tmp.zig:2:29: error: type 'void' is not available in ZON
// tmp.zig:7:50: error: type '[*]const u8' is not available in ZON
// tmp.zig:7:50: note: ZON does not allow many-pointers
// tmp.zig:12:46: error: type 'error{foo}' is not available in ZON
// tmp.zig:17:65: error: type '[*c]const u8' is not available in ZON
// tmp.zig:17:65: note: ZON does not allow C pointers
// tmp.zig:22:49: error: type '[*c]const u8' is not available in ZON
// tmp.zig:22:49: note: ZON does not allow C pointers
// tmp.zig:27:45: error: type '[*c]const u8' is not available in ZON
// tmp.zig:27:45: note: ZON does not allow C pointers
// tmp.zig:32:61: error: type '??u8' is not available in ZON
// tmp.zig:32:61: note: ZON does not allow nested optionals
// tmp.zig:42:29: error: type '??u8' is not available in ZON
// tmp.zig:42:29: note: ZON does not allow nested optionals
// tmp.zig:47:36: error: type '?*const ?u8' is not available in ZON
// tmp.zig:47:36: note: ZON does not allow nested optionals
// tmp.zig:52:50: error: type '?*const ?*const u8' is not available in ZON
// tmp.zig:52:50: note: ZON does not allow nested optionals
// tmp.zig:85:26: error: type '??f32' is not available in ZON
// tmp.zig:85:26: note: ZON does not allow nested optionals
// tmp.zig:90:29: error: type '*i32' is not available in ZON
// tmp.zig:90:29: note: ZON does not allow mutable pointers
// neg_inf.zon:1:1: error: expected type '@Type(.enum_literal)'
// tmp.zig:37:38: note: imported here
// neg_inf.zon:1:1: error: expected type '?u8'
// tmp.zig:57:28: note: imported here
// neg_inf.zon:1:1: error: expected type 'tmp.E'
// tmp.zig:63:26: note: imported here
// neg_inf.zon:1:1: error: expected type 'tmp.U'
// tmp.zig:69:26: note: imported here
// neg_inf.zon:1:1: error: expected type 'tmp.EU'
// tmp.zig:75:27: note: imported here

View file

@ -0,0 +1,21 @@
const C = struct {
c: type,
b: u32,
};
const S = struct {
fn foo(b: u32, c: anytype) void {
bar(C{ .c = c, .b = b });
}
fn bar(_: anytype) void {}
};
pub export fn entry() void {
S.foo(0, u32);
}
// error
//
//:7:25: error: unable to resolve comptime value
//:7:25: note: initializer of comptime-only struct 'tmp.C' must be comptime-known
//:2:8: note: struct requires comptime because of this field
//:2:8: note: types are not available at runtime

View file

@ -0,0 +1,26 @@
var self = "aoeu";
fn f(m: []const u8) void {
m.copy(u8, self[0..], m);
}
export fn entry() usize {
return @sizeOf(@TypeOf(&f));
}
pub export fn entry1() void {
.{}.bar();
}
const S = struct { foo: i32 };
pub export fn entry2() void {
const x = S{ .foo = 1 };
x.bar();
}
// error
//
// :4:6: error: no field or member function named 'copy' in '[]const u8'
// :12:8: error: no field or member function named 'bar' in '@TypeOf(.{})'
// :18:6: error: no field or member function named 'bar' in 'tmp.S'
// :15:11: note: struct declared here

View file

@ -0,0 +1,12 @@
const A = struct { x: u32 };
const T = struct { x: u32 };
export fn foo() void {
const a = A{ .x = 123 };
_ = @as(T, a);
}
// error
//
// :5:16: error: expected type 'tmp.T', found 'tmp.A'
// :1:11: note: struct declared here
// :2:11: note: struct declared here

View file

@ -0,0 +1,52 @@
const S = struct { x: u32 = 0 };
const T = struct { []const u8 };
fn test0() !void {
const x: u8 = try 1;
_ = x;
}
fn test1() !void {
const x: S = try .{};
_ = x;
}
fn test2() !void {
const x: S = try S{ .x = 123 };
_ = x;
}
fn test3() !void {
const x: S = try try S{ .x = 123 };
_ = x;
}
fn test4() !void {
const x: T = try .{"hello"};
_ = x;
}
fn test5() !void {
const x: error{Foo}!u32 = 123;
_ = try try x;
}
comptime {
_ = &test0;
_ = &test1;
_ = &test2;
_ = &test3;
_ = &test4;
_ = &test5;
}
// error
//
// :5:23: error: expected error union type, found 'comptime_int'
// :10:23: error: expected error union type, found '@TypeOf(.{})'
// :15:23: error: expected error union type, found 'tmp.S'
// :1:11: note: struct declared here
// :20:27: error: expected error union type, found 'tmp.S'
// :1:11: note: struct declared here
// :25:23: error: expected error union type, found 'struct { comptime *const [5:0]u8 = "hello" }'
// :31:13: error: expected error union type, found 'u32'

View file

@ -46,14 +46,18 @@ const StructInStruct = struct { a: struct { b: u8 } };
const UnionInStruct = struct { a: union { b: u8 } };
const StructInUnion = union { a: struct { b: u8 } };
const UnionInUnion = union { a: union { b: u8 } };
const StructInTuple = struct { struct { b: u8 } };
const UnionInTuple = struct { union { b: u8 } };
const InnerStruct = struct { b: u8 };
const StructInTuple = struct { a: InnerStruct };
const InnerUnion = union { b: u8 };
const UnionInTuple = struct { a: InnerUnion };
export fn nestedTypes() void {
@compileLog(@typeName(StructInStruct));
@compileLog(@typeName(UnionInStruct));
@compileLog(@typeName(StructInUnion));
@compileLog(@typeName(UnionInUnion));
@compileLog(@typeName(StructInTuple));
@compileLog(@typeName(UnionInTuple));
}
// error
@ -61,22 +65,24 @@ export fn nestedTypes() void {
// :8:5: error: found compile log statement
// :19:5: note: also here
// :39:5: note: also here
// :53:5: note: also here
// :55:5: note: also here
//
// Compile Log Output:
// @as(*const [15:0]u8, "tmp.namespace.S")
// @as(*const [15:0]u8, "tmp.namespace.E")
// @as(*const [15:0]u8, "tmp.namespace.U")
// @as(*const [15:0]u8, "tmp.namespace.O")
// @as(*const [19:0]u8, "tmp.localVarValue.S")
// @as(*const [19:0]u8, "tmp.localVarValue.E")
// @as(*const [19:0]u8, "tmp.localVarValue.U")
// @as(*const [19:0]u8, "tmp.localVarValue.O")
// @as(*const [11:0]u8, "tmp.MakeS()")
// @as(*const [11:0]u8, "tmp.MakeE()")
// @as(*const [11:0]u8, "tmp.MakeU()")
// @as(*const [11:0]u8, "tmp.MakeO()")
// @as(*const [18:0]u8, "tmp.StructInStruct")
// @as(*const [17:0]u8, "tmp.UnionInStruct")
// @as(*const [17:0]u8, "tmp.StructInUnion")
// @as(*const [16:0]u8, "tmp.UnionInUnion")
//Compile Log Output:
//@as(*const [15:0]u8, "tmp.namespace.S")
//@as(*const [15:0]u8, "tmp.namespace.E")
//@as(*const [15:0]u8, "tmp.namespace.U")
//@as(*const [15:0]u8, "tmp.namespace.O")
//@as(*const [19:0]u8, "tmp.localVarValue.S")
//@as(*const [19:0]u8, "tmp.localVarValue.E")
//@as(*const [19:0]u8, "tmp.localVarValue.U")
//@as(*const [19:0]u8, "tmp.localVarValue.O")
//@as(*const [11:0]u8, "tmp.MakeS()")
//@as(*const [11:0]u8, "tmp.MakeE()")
//@as(*const [11:0]u8, "tmp.MakeU()")
//@as(*const [11:0]u8, "tmp.MakeO()")
//@as(*const [18:0]u8, "tmp.StructInStruct")
//@as(*const [17:0]u8, "tmp.UnionInStruct")
//@as(*const [17:0]u8, "tmp.StructInUnion")
//@as(*const [16:0]u8, "tmp.UnionInUnion")
//@as(*const [17:0]u8, "tmp.StructInTuple")
//@as(*const [16:0]u8, "tmp.UnionInTuple")