Implicit integer conversions Before Preconditions
jmh530
john.michael.hall at gmail.com
Tue May 24 20:46:15 UTC 2022
In the code below, `x` and `y` are implicitly converted to `uint`
and `ushort` before the function preconditions are run.
Is there any way to change this behavior? It feels unintuitive
and I can't find in the spec where it says when the conversions
in this case occur, but it clearly happens before the
preconditions are run.
```d
import std.stdio: writeln;
void foo(uint x)
in (x >= 0)
{
writeln(x);
}
void foo(ushort x)
in (x >= 0)
{
writeln(x);
}
void main() {
int x = -1;
foo(x); //prints 4294967295
short y = -1;
foo(y); //prints 65535
}
```
More information about the Digitalmars-d-learn
mailing list