Sema: make orelse with C pointers behave like stage1 for now

Closes #12537
This commit is contained in:
Veikka Tuominen 2022-08-22 00:33:57 +03:00
parent c1afe57d70
commit 74c7782c60
2 changed files with 9 additions and 0 deletions

View File

@ -7261,6 +7261,8 @@ fn zirOptionalPayload(
if (operand_ty.ptrSize() != .C) {
return sema.failWithExpectedOptionalType(block, src, operand_ty);
}
// TODO https://github.com/ziglang/zig/issues/6597
if (true) break :t operand_ty;
const ptr_info = operand_ty.ptrInfo().data;
break :t try Type.ptr(sema.arena, sema.mod, .{
.pointee_type = try ptr_info.pointee_type.copy(sema.arena),

View File

@ -405,3 +405,10 @@ test "optional of noreturn used with orelse" {
const val = NoReturn.testOrelse();
try expect(val == 123);
}
test "orelse on C pointer" {
// TODO https://github.com/ziglang/zig/issues/6597
const foo: [*c]const u8 = "hey";
const d = foo orelse @compileError("bad");
try expectEqual([*c]const u8, @TypeOf(d));
}