1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: permit int -> f32, int64 -> f64 and similar promotions again

This commit is contained in:
Uwe Krüger
2020-06-02 17:00:14 +02:00
committed by GitHub
parent 640688d8cf
commit b0f66a4e05
3 changed files with 19 additions and 11 deletions

View File

@@ -183,17 +183,13 @@ fn (c &Checker) promote_num(left_type, right_type table.Type) table.Type {
}
} else if type_hi.is_float() {
if idx_hi == table.f32_type_idx {
if idx_lo in [table.int_type_idx, table.i64_type_idx, table.u32_type_idx, table.u64_type_idx] {
return table.void_type
} else {
return type_hi
}
} else { // f64, any_flt
if idx_lo in [table.i64_type_idx, table.u64_type_idx] {
return table.void_type
} else {
return type_hi
}
} else { // f64, any_flt
return type_hi
}
} else if idx_lo >= table.byte_type_idx { // both operands are unsigned
return type_hi

View File

@@ -67,3 +67,16 @@ fn test_struct_init_ref_return() {
assert fabs(fabs(x.get()) - 3.890949634755863) < 1.e-6
}
fn test_f32_int() {
x := f32(15.25)
y := -3
assert x + y == 12.25
assert y + x == 12.25
a := u32(34)
assert a + x == 49.25
b := i64(-17)
c := 16.75
assert c + b == -0.25
d := u64(300)
assert d + c == 316.75
}