diff --git a/src/ir.cpp b/src/ir.cpp index 3e2b75822e..20067b74d1 100644 --- a/src/ir.cpp +++ b/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; diff --git a/test/compile_errors.zig b/test/compile_errors.zig index e8b7e610ee..79ecaee7c1 100644 --- a/test/compile_errors.zig +++ b/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'", }); }