Commit 74c7782c60

Veikka Tuominen <git@vexu.eu>
2022-08-21 23:33:57
Sema: make orelse with C pointers behave like stage1 for now
Closes #12537
1 parent c1afe57
Changed files (2)
src
test
behavior
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),
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));
+}