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

Closes #5832
master
Vexu 2020-07-09 21:25:55 +03:00
parent a489ea0b2f
commit 2e1bdd0d14
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
2 changed files with 14 additions and 1 deletions

View File

@ -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) {

View File

@ -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);