authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-22 00:33:57+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-22 11:16:36+03:00
log74c7782c6083d398a4f0f126a4597c605d5223cd
tree425012fe2ac6e628e40fe1caa25929eb84e7b4c5
parentc1afe57d70606a20af42cb761b4919765295dcd4

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

Closes #12537

2 files changed, 9 insertions(+), 0 deletions(-)

src/Sema.zig+2
...@@ -7261,6 +7261,8 @@ fn zirOptionalPayload(...@@ -7261,6 +7261,8 @@ fn zirOptionalPayload(
7261 if (operand_ty.ptrSize() != .C) {7261 if (operand_ty.ptrSize() != .C) {
7262 return sema.failWithExpectedOptionalType(block, src, operand_ty);7262 return sema.failWithExpectedOptionalType(block, src, operand_ty);
7263 }7263 }
7264 // TODO https://github.com/ziglang/zig/issues/6597
7265 if (true) break :t operand_ty;
7264 const ptr_info = operand_ty.ptrInfo().data;7266 const ptr_info = operand_ty.ptrInfo().data;
7265 break :t try Type.ptr(sema.arena, sema.mod, .{7267 break :t try Type.ptr(sema.arena, sema.mod, .{
7266 .pointee_type = try ptr_info.pointee_type.copy(sema.arena),7268 .pointee_type = try ptr_info.pointee_type.copy(sema.arena),
test/behavior/optional.zig+7
...@@ -405,3 +405,10 @@ test "optional of noreturn used with orelse" {...@@ -405,3 +405,10 @@ test "optional of noreturn used with orelse" {
405 const val = NoReturn.testOrelse();405 const val = NoReturn.testOrelse();
406 try expect(val == 123);406 try expect(val == 123);
407}407}
408
409test "orelse on C pointer" {
410 // TODO https://github.com/ziglang/zig/issues/6597
411 const foo: [*c]const u8 = "hey";
412 const d = foo orelse @compileError("bad");
413 try expectEqual([*c]const u8, @TypeOf(d));
414}