This issue has been moved from a ticket on Developer Community.
Is this really the expected and documented compiler behaviour, that casting an integral to uint is in reality producing something different, that to really get an uint you need to cast that to uint? Issue title was selected from the expectation not even the C# language specification can be that messed up, and this is therefore a compiler bug.
class C
{
static uint fn(sbyte a, sbyte b)
{
uint ret;
ret = (uint)(a << 8) | (uint)b; // CS0675
ret = (uint)(uint)(a << 8) | (uint)b; // CS0675
ret = (uint)(a << 8) | (uint) (uint)b;
ret = (uint)(uint)(a << 8) | (uint) (uint)b;
return ret;
}
}
that is, the only way to silence the compiler warning is to twice cast the second operand of the binary operation to the target type!
The type of the statement (uint)b shall be uint, only uint and nothing but uint. It can be nothing else, the explicit cast tells the compiler it is so. Yet the compiler seemingly thinks it's not (without telling us what it has really converted that into).
Original Comments
Visual Studio Feedback System on 3/22/2020, 06:46 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Original Solutions
(no solutions)
This issue has been moved from a ticket on Developer Community.
Is this really the expected and documented compiler behaviour, that casting an integral to
uintis in reality producing something different, that to really get anuintyou need to cast that touint? Issue title was selected from the expectation not even the C# language specification can be that messed up, and this is therefore a compiler bug.that is, the only way to silence the compiler warning is to twice cast the second operand of the binary operation to the target type!
The type of the statement
(uint)bshall beuint, onlyuintand nothing butuint. It can be nothing else, the explicit cast tells the compiler it is so. Yet the compiler seemingly thinks it's not (without telling us what it has really converted that into).Original Comments
Visual Studio Feedback System on 3/22/2020, 06:46 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Original Solutions
(no solutions)