Commit 78d8931647
Changed files (2)
src
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'",
});
}