| author | |
| committer | |
| log | 0fa24b6b7568557c29c9b3ee213ce2b06fcd6367 |
| tree | aac947ab8d58bb797bcadf5076729312fbbebb4f |
| parent | 9b56efc957dfb70ab70a74df3da55a9215e27b8d |
2 files changed, 18 insertions(+), 1 deletions(-)
src/ir.cpp+1-1| ... | @@ -9408,7 +9408,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -9408,7 +9408,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc |
| 9408 | if (type_is_invalid(casted_payload->value.type)) | 9408 | if (type_is_invalid(casted_payload->value.type)) |
| 9409 | return ira->codegen->invalid_instruction; | 9409 | return ira->codegen->invalid_instruction; |
| 9410 | 9410 | ||
| 9411 | ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad); | 9411 | ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefOk); |
| 9412 | if (!val) | 9412 | if (!val) |
| 9413 | return ira->codegen->invalid_instruction; | 9413 | return ira->codegen->invalid_instruction; |
| 9414 | 9414 |
test/cases/cast.zig+17| ... | @@ -468,3 +468,20 @@ test "@intCast i32 to u7" { | ... | @@ -468,3 +468,20 @@ test "@intCast i32 to u7" { |
| 468 | var z = x >> @intCast(u7, y); | 468 | var z = x >> @intCast(u7, y); |
| 469 | assert(z == 0xff); | 469 | assert(z == 0xff); |
| 470 | } | 470 | } |
| 471 | |||
| 472 | test "implicit cast undefined to optional" { | ||
| 473 | assert(MakeType(void).getNull() == null); | ||
| 474 | assert(MakeType(void).getNonNull() != null); | ||
| 475 | } | ||
| 476 | |||
| 477 | fn MakeType(comptime T: type) type { | ||
| 478 | return struct { | ||
| 479 | fn getNull() ?T { | ||
| 480 | return null; | ||
| 481 | } | ||
| 482 | |||
| 483 | fn getNonNull() ?T { | ||
| 484 | return T(undefined); | ||
| 485 | } | ||
| 486 | }; | ||
| 487 | } |