authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-09 21:25:55+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-09 21:25:55+03:00
log2e1bdd0d14f490a80bbed3ee0e0479a908715d33
tree491a48c67d5ac87b6e776d483065a5bf80027481
parenta489ea0b2f38c67025c2b2424749a9a7320cdd5a
signaturelock-open Commit is signed but in an unrecognized format.

use correct cast function when doing `@floatCast` at comptime

Closes #5832

2 files changed, 14 insertions(+), 1 deletions(-)

src/ir.cpp+1-1
......@@ -26718,7 +26718,7 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo
2671826718 }
2671926719
2672026720 if (instr_is_comptime(target) || dest_type->id == ZigTypeIdComptimeFloat) {
26721 return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type);
26721 return ir_analyze_widen_or_shorten(ira, &instruction->target->base, target, dest_type);
2672226722 }
2672326723
2672426724 if (target->value->type->id != ZigTypeIdFloat) {
test/stage1/behavior/cast.zig+13
......@@ -384,6 +384,19 @@ test "@intCast i32 to u7" {
384384 expect(z == 0xff);
385385}
386386
387test "@floatCast cast down" {
388 {
389 var double: f64 = 0.001534;
390 var single = @floatCast(f32, double);
391 expect(@TypeOf(single) == f32);
392 }
393 {
394 const double: f64 = 0.001534;
395 const single = @floatCast(f32, double);
396 expect(@TypeOf(single) == f32);
397 }
398}
399
387400test "implicit cast undefined to optional" {
388401 expect(MakeType(void).getNull() == null);
389402 expect(MakeType(void).getNonNull() != null);