zig/test/behavior
Martin Hafskjold Thoresen 07f64a2e13 Sema: error on ambiguous coercion of comptime float and ints
The following, from the documentation as of the time of writing, illustrates
the problem:

```zig
// Compile time coercion of float to int
test "implicit cast to comptime_int" {
    var f: f32 = 54.0 / 5;
    _ = f;
}
```

It is not clear how to unify the types of 54.0 and 5 to perform the
division. We can either

 - cast 54.0 to comptime_int resulting in @as(comptime_int, 10), which is
   casted to @as(f32, 10), or
 - cast 5 to comptime_float resulting in @as(comptime_float, 10.8), which
   is casted to @as(f32, 10.8)

Since the two resulting values are different, a compiler error is appropriate.

If we know that casting to either type will result in the same value we
don't need to error.  For instance, 10.0 / 2 is okay, as is 10 / 2.0.

Fixes: #12364
2022-08-17 14:09:09 -07:00
..
2022-02-28 23:20:05 +01:00
2022-07-14 18:11:46 -07:00
2021-10-28 17:33:05 -07:00
2022-03-18 15:02:52 -07:00
2022-08-10 16:13:59 -07:00
2022-02-13 14:42:20 +02:00
2022-06-08 15:51:48 -07:00
2022-08-10 15:18:09 -04:00
2022-07-14 18:11:46 -07:00
2022-01-07 00:06:06 -05:00
2022-02-22 21:57:42 +01:00
2022-03-05 11:31:51 +01:00
2022-08-10 16:43:47 -07:00
2022-03-18 00:12:22 -07:00
2022-03-18 15:02:52 -07:00