diff --git a/src/ir.cpp b/src/ir.cpp index d16c8a5e36..2b3b5f877b 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -11592,7 +11592,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted wanted_ptr_type->data.pointer.sentinel == nullptr || (actual_ptr_type->data.pointer.sentinel != nullptr && const_values_equal(ira->codegen, wanted_ptr_type->data.pointer.sentinel, - actual_ptr_type->data.pointer.sentinel)); + actual_ptr_type->data.pointer.sentinel)) || + actual_ptr_type->data.pointer.ptr_len == PtrLenC; if (!ok_null_term_ptrs) { result.id = ConstCastResultIdPtrSentinel; result.data.bad_ptr_sentinel = allocate_nonzero(1); diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index fe55b445a8..a70467e199 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -768,3 +768,17 @@ test "variable initialization uses result locations properly with regards to the const x: i32 = if (b) 1 else 2; expect(x == 1); } + +test "cast between [*c]T and ?[*:0]T on fn parameter" { + const S = struct { + const Handler = ?extern fn ([*c]const u8) void; + fn addCallback(handler: Handler) void {} + + fn myCallback(cstr: ?[*:0]const u8) callconv(.C) void {} + + fn doTheTest() void { + addCallback(myCallback); + } + }; + S.doTheTest(); +}