diff --git a/src/ir.cpp b/src/ir.cpp index 0804134d2a..35b6b4cef4 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -9408,7 +9408,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc if (type_is_invalid(casted_payload->value.type)) return ira->codegen->invalid_instruction; - ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad); + ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefOk); if (!val) return ira->codegen->invalid_instruction; diff --git a/test/cases/cast.zig b/test/cases/cast.zig index 5688d90e11..63cc6313e1 100644 --- a/test/cases/cast.zig +++ b/test/cases/cast.zig @@ -468,3 +468,20 @@ test "@intCast i32 to u7" { var z = x >> @intCast(u7, y); assert(z == 0xff); } + +test "implicit cast undefined to optional" { + assert(MakeType(void).getNull() == null); + assert(MakeType(void).getNonNull() != null); +} + +fn MakeType(comptime T: type) type { + return struct { + fn getNull() ?T { + return null; + } + + fn getNonNull() ?T { + return T(undefined); + } + }; +}