Closed
Description
Platform: Windows / Linux
runtime: dotnet 2.1.403
code optimization enabled
The code:
[Test]
public void BugRepro()
{
byte[] valueBytes = new byte[] { 0x7f, 0xff };
byte firstByte = valueBytes[0];
byte secondByte = valueBytes[1];
// (firstByte << 8) should be inferred as int as in other targets and as without optimization
ushort guilty = (ushort)((firstByte << 8) | secondByte);
guilty.Should().Be(32767);
}
Actual outcome:
guilty == 255
Most likely (firstByte << 8) is inferred as byte with compile time optimization enabled, and guilty is evalueated as (0 | 0xff)
It works as expected without code optimization in netcore2.1. All other targets: net462, mono, netcore2.0 produce expected result
Metadata
Metadata
Assignees
Labels
No labels