d隐式整转换
import std.stdio: writeln;
void foo(uint x)
in (x >= 0)
{//删除该前条件,因为x为`正`总是`>=0`.
writeln(x);
}
void foo(ushort x)
in (x >= 0)
{
writeln(x);
}
void main() {
int x = -1;
foo(x); //打印4294967295
short y =-1;
foo(y); //打印65535
}
前条件
运行前,隐式转换xy
为正/正短
.