Skip to content

Commit 74c7782

Browse files
committed
Sema: make orelse with C pointers behave like stage1 for now
Closes #12537
1 parent c1afe57 commit 74c7782

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Sema.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7261,6 +7261,8 @@ fn zirOptionalPayload(
72617261
if (operand_ty.ptrSize() != .C) {
72627262
return sema.failWithExpectedOptionalType(block, src, operand_ty);
72637263
}
7264+
// TODO https://github.com/ziglang/zig/issues/6597
7265+
if (true) break :t operand_ty;
72647266
const ptr_info = operand_ty.ptrInfo().data;
72657267
break :t try Type.ptr(sema.arena, sema.mod, .{
72667268
.pointee_type = try ptr_info.pointee_type.copy(sema.arena),

test/behavior/optional.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,10 @@ test "optional of noreturn used with orelse" {
405405
const val = NoReturn.testOrelse();
406406
try expect(val == 123);
407407
}
408+
409+
test "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+
}

0 commit comments

Comments
 (0)