-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
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
Improve enum #2763
Comments
Hi @siegfriedpammer, I have investigated the issue. The replacement of enum with int happens somewhere inside StatementTransform. I can catch the moment when this replacement happens. In this stack trace, there is such a comment: // TODO: inlining of small integer types might be semantically incorrect,
// but we can't avoid it this easily without breaking lots of tests. Can it be related? Does it make sense to try to fix it or does it look like a potentially major change? |
That's unrelated, with "small integer types" that comment means types smaller than |
Enum in switch was replaced with the int incorrectly in some cases.
@dgrunwald Also, I found another bug. public static void EnumReplacedWithIntIncorrectly_AndIncorrectConditionGenerated_AndUnusedVariables(int intValue)
{
var color = (KnownColor)intValue;
var color2 = (KnownColor)intValue;
var color3 = (KnownColor)intValue;
if (color == KnownColor.DarkBlue)
{
}
if (color2 == KnownColor.DarkBlue)
{
}
} is generated like this: public static void EnumReplacedWithIntIncorrectly_AndIncorrectConditionGenerated_AndUnusedVariables(int intValue)
{
KnownColor color = (KnownColor)intValue;
KnownColor color2 = (KnownColor)intValue;
if (color == KnownColor.DarkBlue)
{
}
if (color2 != KnownColor.DarkBlue)// '!=' instead of '==' here
{
}
} Do you remember if it was already registered? One more question. I tried to use pre-commit script as required, but I constantly get an error even though no spaces were introduced (only tabs). Is pre-commit script supported and working correctly now? |
Empty blocks cannot be distinguished, so the code is effectively semantically equivalent, and the conditions entirely depend on the generated IL code. If you add statements to the bodies, the code is decompiled exactly as expected: |
Which version of dotnet-format are you using? Our experience is that it is quite fragile and will break easily, that's why we use one specific version, as can be seen here: https://github.com/icsharpcode/ILSpy/blob/master/.github/workflows/build-ilspy.yml#L33 |
Original :
ILSpy :
The text was updated successfully, but these errors were encountered: