dlang.org/type.html gives this example ubyte u1 = cast(byte)-1; // error, -1 cannot be represented in a ubyte ushort u2 = cast(short)-1; // error, -1 cannot be represented in a ushort uint u3 = cast(int)-1; // ok, -1 can be represented in a uint ulong u4 = cast(long)-1; // ok, -1 can be represented in a ulong However, all 4 compile, which makes sense, because casts are blunt and don't care about what does and doesn't fit. This won't compile ubyte u1 = -1; ushort u2 = -1; which is a bit interesting given that this compiles just fine byte i1 = -1; short i2 = -1; ubyte u1 = i1; ushort u2 = i2; But regardless of whether ubyte u1 = -1; ushort u2 = -1; should compile, the example in documentation definitely should, and the documentation claims that it shouldn't, so the documentation is wrong and needs to be updated. And honestly, I don't understand the logic of how -1 can be represented in a uint but not a ushort like the docs claim, since it can't be represented in either, since they're unsigned, so I don't understand how the example in the docs ever would have made sense.
@matthriscu created dlang/dlang.org pull request #3517 "Fix issue 11493 - Correctly explain code snippet behaviour" fixing this issue: - Fix 11493 - correctly explain code snippet behaviour Signed-off-by: Matei Hriscu <matei.hriscu@proton.me> https://github.com/dlang/dlang.org/pull/3517
dlang/dlang.org pull request #3517 "Fix issue 11493 - Correctly explain code snippet behaviour" was merged into master: - deb0d0a8328f79223906d13aed8964f43663281b by Matei Hriscu: Fix 11493 - correctly explain code snippet behaviour Signed-off-by: Matei Hriscu <matei.hriscu@proton.me> https://github.com/dlang/dlang.org/pull/3517