-
Notifications
You must be signed in to change notification settings - Fork 831
Description
In the attached example, we create three types;
- ID, in ClassLibrary1
- ID2, in ClassLibrary1, which relies on ID
- ID3 in ConsoleApp1, which relies on ID2.
In each of these we override equality and comparison operators, using inline functions to improve performance for ID3. (Note that this repro is a minimal example from more complicated code where this makes more sense!)
We create instances of each in the console app. and check that two unequal values of each type are reported as unequal by the compiler.
In Release mode only, the third assertion, that two obviously different instances of ID3 are unequal fails.
To repro, please run the attached program.
repro.zip
Expected behavior
I expect the program to exit with code 0.
Actual behavior
An exception is thrown in the last equality check, for aBarBar versus bBarBar
Known workarounds
Running this in debug mode fixes the issue.
Putting the definitions of ID and ID2 in the same project as ID3 fixes the issue. Because of this, I suspect this issue is something to do with incorrect optimisations around inlining functions from other projects.
Changing ID from a struct into a class by removing all the attributes associated with it fixes the issue.
Related information
Tested in .NET 8, SDKs 8.0.100 and 8.0.403
Windows 10.
VS 2022 for editing.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status