Merge pull request #11837 from Vexu/stage2
Fix (nearly) all stage2 crashes when testing stdlib
This commit is contained in:
@@ -1086,3 +1086,26 @@ test "inline call of function with a switch inside the return statement" {
|
||||
};
|
||||
try expect(S.foo(1) == 1);
|
||||
}
|
||||
|
||||
test "namespace lookup ignores decl causing the lookup" {
|
||||
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
|
||||
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
|
||||
|
||||
const S = struct {
|
||||
fn Mixin(comptime T: type) type {
|
||||
return struct {
|
||||
fn foo() void {
|
||||
const set = std.EnumSet(T.E).init(undefined);
|
||||
_ = set;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const E = enum { a, b };
|
||||
usingnamespace Mixin(@This());
|
||||
};
|
||||
_ = S.foo();
|
||||
}
|
||||
|
||||
@@ -1426,6 +1426,7 @@ test "coerce undefined single-item pointer of array to error union of slice" {
|
||||
}
|
||||
|
||||
test "pointer to empty struct literal to mutable slice" {
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||
var x: []i32 = &.{};
|
||||
try expect(x.len == 0);
|
||||
}
|
||||
|
||||
@@ -453,65 +453,6 @@ test "optional error set is the same size as error set" {
|
||||
comptime try expect(S.returnsOptErrSet() == null);
|
||||
}
|
||||
|
||||
test "optional error set with only one error is the same size as bool" {
|
||||
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
|
||||
const E = error{only};
|
||||
comptime try expect(@sizeOf(?E) == @sizeOf(bool));
|
||||
comptime try expect(@alignOf(?E) == @alignOf(bool));
|
||||
const S = struct {
|
||||
fn gimmeNull() ?E {
|
||||
return null;
|
||||
}
|
||||
fn gimmeErr() ?E {
|
||||
return error.only;
|
||||
}
|
||||
};
|
||||
try expect(S.gimmeNull() == null);
|
||||
try expect(error.only == S.gimmeErr().?);
|
||||
comptime try expect(S.gimmeNull() == null);
|
||||
comptime try expect(error.only == S.gimmeErr().?);
|
||||
}
|
||||
|
||||
test "optional empty error set" {
|
||||
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
|
||||
|
||||
comptime try expect(@sizeOf(error{}!void) == @sizeOf(void));
|
||||
comptime try expect(@alignOf(error{}!void) == @alignOf(void));
|
||||
|
||||
var x: ?error{} = undefined;
|
||||
if (x != null) {
|
||||
@compileError("test failed");
|
||||
}
|
||||
}
|
||||
|
||||
test "empty error set plus zero-bit payload" {
|
||||
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
|
||||
comptime try expect(@sizeOf(error{}!void) == @sizeOf(void));
|
||||
comptime try expect(@alignOf(error{}!void) == @alignOf(void));
|
||||
|
||||
var x: error{}!void = undefined;
|
||||
if (x) |payload| {
|
||||
if (payload != {}) {
|
||||
@compileError("test failed");
|
||||
}
|
||||
} else |_| {
|
||||
@compileError("test failed");
|
||||
}
|
||||
const S = struct {
|
||||
fn empty() error{}!void {}
|
||||
fn inferred() !void {
|
||||
return empty();
|
||||
}
|
||||
};
|
||||
try S.inferred();
|
||||
}
|
||||
|
||||
test "nested catch" {
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
|
||||
@@ -137,43 +137,8 @@ const A_Enum = enum {
|
||||
|
||||
fn regular() void {}
|
||||
|
||||
test "fn body decl" {
|
||||
if (builtin.zig_backend == .stage1) {
|
||||
// stage1 fails to return fully qualified namespaces.
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
|
||||
if (builtin.zig_backend == .stage2_c) 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
|
||||
|
||||
try B.doTest();
|
||||
}
|
||||
|
||||
const B = struct {
|
||||
fn doTest() !void {
|
||||
const B_Struct = struct {};
|
||||
const B_Union = union {
|
||||
unused: u8,
|
||||
};
|
||||
const B_Enum = enum {
|
||||
unused,
|
||||
};
|
||||
|
||||
try expectEqualStringsIgnoreDigits(
|
||||
"behavior.typename.B.doTest__struct_0",
|
||||
@typeName(B_Struct),
|
||||
);
|
||||
try expectEqualStringsIgnoreDigits(
|
||||
"behavior.typename.B.doTest__union_0",
|
||||
@typeName(B_Union),
|
||||
);
|
||||
try expectEqualStringsIgnoreDigits(
|
||||
"behavior.typename.B.doTest__enum_0",
|
||||
@typeName(B_Enum),
|
||||
);
|
||||
}
|
||||
fn doTest() !void {}
|
||||
};
|
||||
|
||||
test "fn param" {
|
||||
@@ -246,3 +211,27 @@ pub fn expectEqualStringsIgnoreDigits(expected: []const u8, actual: []const u8)
|
||||
}
|
||||
return expectEqualStrings(expected, actual_buf[0..actual_i]);
|
||||
}
|
||||
|
||||
test "local variable" {
|
||||
if (builtin.zig_backend == .stage1) {
|
||||
// stage1 fails to return fully qualified namespaces.
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
|
||||
if (builtin.zig_backend == .stage2_c) 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
|
||||
|
||||
const Foo = struct { a: u32 };
|
||||
const Bar = union { a: u32 };
|
||||
const Baz = enum { a, b };
|
||||
const Qux = enum { a, b };
|
||||
const Quux = enum { a, b };
|
||||
|
||||
try expectEqualStrings("behavior.typename.test.local variable.Foo", @typeName(Foo));
|
||||
try expectEqualStrings("behavior.typename.test.local variable.Bar", @typeName(Bar));
|
||||
try expectEqualStrings("behavior.typename.test.local variable.Baz", @typeName(Baz));
|
||||
try expectEqualStrings("behavior.typename.test.local variable.Qux", @typeName(Qux));
|
||||
try expectEqualStrings("behavior.typename.test.local variable.Quux", @typeName(Quux));
|
||||
}
|
||||
|
||||
@@ -1183,3 +1183,21 @@ test "comptime equality of extern unions with same tag" {
|
||||
const b = S.U{ .a = 1234 };
|
||||
try expect(S.foo(a) == S.foo(b));
|
||||
}
|
||||
|
||||
test "union tag is set when initiated as a temporary value at runtime" {
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
|
||||
const U = union(enum) {
|
||||
a,
|
||||
b: u32,
|
||||
c,
|
||||
|
||||
fn doTheTest(u: @This()) !void {
|
||||
try expect(u == .b);
|
||||
}
|
||||
};
|
||||
var b: u32 = 1;
|
||||
try (U{ .b = b }).doTheTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user