diff --git a/src/ir.cpp b/src/ir.cpp index a45455ad39e03c5354ed1b7883c547628db85502..81b7f14f84db7a0bdd78ff8eb0a0f1151bcaacc8 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -26718,7 +26718,7 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo } if (instr_is_comptime(target) || dest_type->id == ZigTypeIdComptimeFloat) { - return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type); + return ir_analyze_widen_or_shorten(ira, &instruction->target->base, target, dest_type); } if (target->value->type->id != ZigTypeIdFloat) { diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index 77cdacc307a860a98d45c29f281b8d33b84000b3..4325b0b9e40788824a9e74f9bad6239ea803da40 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -384,6 +384,19 @@ test "@intCast i32 to u7" { expect(z == 0xff); } +test "@floatCast cast down" { + { + var double: f64 = 0.001534; + var single = @floatCast(f32, double); + expect(@TypeOf(single) == f32); + } + { + const double: f64 = 0.001534; + const single = @floatCast(f32, double); + expect(@TypeOf(single) == f32); + } +} + test "implicit cast undefined to optional" { expect(MakeType(void).getNull() == null); expect(MakeType(void).getNonNull() != null);