Sema: fix comptime @floatCast downcast

This commit is contained in:
Andrew Kelley 2022-05-18 14:46:04 -07:00
parent 58943fc627
commit 5626bb45d2
2 changed files with 5 additions and 3 deletions

View File

@ -7236,8 +7236,8 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
),
}
if (try sema.isComptimeKnown(block, operand_src, operand)) {
return sema.coerce(block, dest_ty, operand, operand_src);
if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |operand_val| {
return sema.addConstant(dest_ty, try operand_val.floatCast(sema.arena, dest_ty, target));
}
if (dest_is_comptime_float) {
return sema.fail(block, src, "unable to cast runtime value to 'comptime_float'", .{});

View File

@ -630,7 +630,9 @@ test "vector casts" {
}
test "@floatCast cast down" {
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
{
var double: f64 = 0.001534;