mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
allow implicit cast of undefined to optional
This commit is contained in:
parent
9b56efc957
commit
0fa24b6b75
@ -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;
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user