Commit 78d8931647

arbrk1 <arbrk1@users.noreply.github.com>
2020-06-25 05:58:50
Fix issue #5618 (#5685)
* fix issue #5618 * A test for the issue #5618 added. Also inserted a comma in the neighboring test to make it more zigfmt-friendly.
1 parent 2fde824
Changed files (2)
src/ir.cpp
@@ -15452,6 +15452,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
     if (is_pointery_and_elem_is_not_pointery(actual_type)) {
         ZigType *dest_ptr_type = nullptr;
         if (wanted_type->id == ZigTypeIdPointer &&
+            actual_type->id != ZigTypeIdOptional &&
             wanted_type->data.pointer.child_type == ira->codegen->builtin_types.entry_c_void)
         {
             dest_ptr_type = wanted_type;
test/compile_errors.zig
@@ -7571,6 +7571,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
         \\    return -y;
         \\}
     , &[_][]const u8{
-        "tmp.zig:3:12: error: negation of type 'u32'"
+        "tmp.zig:3:12: error: negation of type 'u32'",
+    });
+
+    cases.add("Issue #5618: coercion of ?*c_void to *c_void must fail.",
+        \\export fn foo() void {
+        \\    var u: ?*c_void = null;
+        \\    var v: *c_void = undefined;
+        \\    v = u;
+        \\}
+    , &[_][]const u8{
+        "tmp.zig:4:9: error: expected type '*c_void', found '?*c_void'",
     });
 }