diff --git a/src/Sema.zig b/src/Sema.zig index 24bbdb0b0c0e9b220be2f01013ebd9b5ee31e993..2355e8374d557668770da184fda2e0180482ef77 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -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), diff --git a/test/behavior/optional.zig b/test/behavior/optional.zig index c13a3b7e4fd2c82de872d373bf10d9fbb7c7e78a..28261daf1f97242558522dad2468e6f400260c44 100644 --- a/test/behavior/optional.zig +++ b/test/behavior/optional.zig @@ -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)); +}