Deprecate implicit conversion between signed and unsigned integers
Quirin Schroll
qs.il.paperinik at gmail.com
Thu Feb 13 22:53:01 UTC 2025
On Thursday, 6 February 2025 at 20:52:53 UTC, Walter Bright wrote:
> On 2/6/2025 7:18 AM, Quirin Schroll wrote:
>> 4. Micro-lossy narrowing conversions:
>> * `int`/`uint` → `float`
>> * `long`/`ulong` → `float`/`double`
>
> We already do VRP checks for cases:
>
> ```
> float f = 1; // passes
> float g = 0x1234_5678; // fails
> ```
I didn’t know that, but I hardly ever use floating-point types.
However, that’s not exactly VRP, but a useful check that
compile-time-known values are representable in the target type.
VRP means that while you normally need a cast to assign an
integer to a `ubyte`, you can assign `myInt & 0xFF` to a `ubyte`
without cast. You *can* assign any run-time `int` to a `float`.
What you’re pointing out is that “micro-lossy narrowing
conversions” are a compile-error if they’re *definitely*
occurring.
More information about the dip.ideas
mailing list