We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Here's a small project that reproduces the issue:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net5.0</TargetFramework> </PropertyGroup> <PropertyGroup> <Optimize>true</Optimize> <RootAllApplicationAssemblies>false</RootAllApplicationAssemblies> <IlcInvariantGlobalization>true</IlcInvariantGlobalization> <IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata> <IlcDisableReflection>true</IlcDisableReflection> <IlcOptimizationPreference>Speed</IlcOptimizationPreference> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="6.0.0-*" /> </ItemGroup> </Project>
using System; namespace BugNativeAOT { internal class Program { private readonly struct Size { public int Width { get; } public int Height { get; } public long Area => Width * (long)Height; public Size(int width, int height) { Width = width; Height = height; } } private sealed class Bug { public Bug(Size s) { S = s; } public Size S { get; } } private static void Main(string[] args) { var t = new Bug(new Size(0, 0)); if (t.S.Area == 0L) { Console.WriteLine("Expected: == operator"); } else { Console.WriteLine("UNEXPECTED: == operator"); Console.WriteLine($"Area value = {t.S.Area}"); } if (0L.Equals(t.S.Area)) { Console.WriteLine("Expected: long.Equals"); } else { Console.WriteLine("UNEXPECTED: == long.Equals"); Console.WriteLine($"Area value = {t.S.Area}"); } if (((object)t.S.Area).Equals(0L)) { Console.WriteLine("Expected: object.Equals boxed"); } else { Console.WriteLine("UNEXPECTED: == object.Equals boxed"); Console.WriteLine($"Area value = {t.S.Area}"); } } } }
The output is
UNEXPECTED: == operator Area value = 0 UNEXPECTED: == long.Equals Area value = 0 Expected: object.Equals boxed
I haven't tested other types and I'm not sure the example is exactly minimal, but it reproduces the bug I found when using something similar.
NOTE: if I disable the optimizations in the .csproj, the program outputs the expected results.
The text was updated successfully, but these errors were encountered:
Thank you for reporting this!
This bug is fixed in dotnet/runtime repo already. I am going to submit a merge today to pick up the fix.
Sorry, something went wrong.
Fixed by #1215. The nuget package with the fix should be available on the feed in a few hours.
Thank you very much @jkotas. Tomorrow I'll give it a try. Just out of curiosity, and if it is not too much trouble, which commit fixes this?
It was fixed by dotnet/runtime#53806
No branches or pull requests
Here's a small project that reproduces the issue:
The output is
I haven't tested other types and I'm not sure the example is exactly minimal, but it reproduces the bug I found when using something similar.
NOTE: if I disable the optimizations in the .csproj, the program outputs the expected results.
The text was updated successfully, but these errors were encountered: