stage2: actually coerce in coerce_result_ptr at comptime

This commit is contained in:
Veikka Tuominen
2022-02-25 12:54:40 +02:00
committed by Andrew Kelley
parent b3aa1ab693
commit ee149aaa03
5 changed files with 63 additions and 10 deletions

View File

@@ -371,7 +371,9 @@ fn testPeerResolveArrayConstSlice(b: bool) !void {
}
test "implicitly cast from T to anyerror!?T" {
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
try castToOptionalTypeError(1);
comptime try castToOptionalTypeError(1);
@@ -387,7 +389,7 @@ fn castToOptionalTypeError(z: i32) !void {
const f = z;
const g: anyerror!?i32 = f;
_ = g catch {};
_ = try g;
const a = A{ .a = z };
const b: anyerror!?A = a;

View File

@@ -294,10 +294,11 @@ fn quux_1() !i32 {
}
test "error: Zero sized error set returned with value payload crash" {
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
_ = foo3(0) catch {};
_ = comptime foo3(0) catch {};
_ = try foo3(0);
_ = comptime try foo3(0);
}
const Error = error{};

View File

@@ -1237,3 +1237,28 @@ test "anon init through error union" {
try S.doTheTest();
comptime try S.doTheTest();
}
test "typed init through error unions and optionals" {
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
if (builtin.zig_backend != .stage2_llvm) return error.SkipZigTest; // TODO
const S = struct {
a: u32,
fn foo() anyerror!?anyerror!@This() {
return @This(){ .a = 1 };
}
fn bar() ?anyerror![2]u8 {
return [2]u8{ 1, 2 };
}
fn doTheTest() !void {
var a = try (try foo()).?;
var b = try bar().?;
try expect(a.a + b[1] == 3);
}
};
try S.doTheTest();
comptime try S.doTheTest();
}