On Wednesday, 11 January 2023 at 13:51:43 UTC, jmh530 wrote:
>The problem is the combination with assignment, which is what makes it seem like a bug. According to [1], "the right operand is implicitly converted to the type of the left operand, and assigned to it."
[1] https://dlang.org/spec/expression.html#simple_assignment_expressions
The relevant section of the spec here is the one about "Assignment Operator Expressions" [2], which states that
>For arguments of built-in types, assignment operator expressions such as
a op= b
are semantically equivalent to:
a = cast(typeof(a))(a op b)
If we rewrite deadalnix's example using this equivalence, we get the following code:
ushort ee = 1028;
ee = cast(ushort)(ee << 5U);
ee = cast(ushort)(ee >> 5U);
writeln(ee);
...which prints 1028. So the behavior of the original example is unambiguously a violation of the language spec.
[2] https://dlang.org/spec/expression.html#assignment_operator_expressions