Fix enum conversion bug #1212#1228
Draft
GrahamTheCoder wants to merge 5 commits intoicsharpcode:masterfrom
Draft
Fix enum conversion bug #1212#1228GrahamTheCoder wants to merge 5 commits intoicsharpcode:masterfrom
GrahamTheCoder wants to merge 5 commits intoicsharpcode:masterfrom
Conversation
- Modified TypeConversionAnalyzer.cs to use EnumCastThenConversion for all non-enum types, ensuring that the necessary cast through the underlying type is generated (e.g. `(MyType)(int)MyEnum.Value1`). - Added unit test Issue1211_EnumToCustomTypeImplicitConversionAsync to ensure regressions don't occur. Co-authored-by: GrahamTheCoder <2490482+GrahamTheCoder@users.noreply.github.com>
- Modified TypeConversionAnalyzer.cs to use EnumCastThenConversion for all non-enum types, ensuring that the necessary cast through the underlying type is generated (e.g. `(MyType)(int)MyEnum.Value1`). - Added unit test Issue1211_EnumToCustomTypeImplicitConversionAsync to ensure regressions don't occur. Co-authored-by: GrahamTheCoder <2490482+GrahamTheCoder@users.noreply.github.com>
- Modified TypeConversionAnalyzer.cs to use EnumCastThenConversion for all non-enum types, ensuring that the necessary cast through the underlying type is generated (e.g. `(MyType)(int)MyEnum.Value1`). - Added unit test Issue1211_EnumToCustomTypeImplicitConversionAsync to ensure regressions don't occur. Co-authored-by: GrahamTheCoder <2490482+GrahamTheCoder@users.noreply.github.com>
- Update TypeConversionAnalyzer to only use EnumCastThenConversion if the target type is not an Enum and does not have a defined Conversions.To method. - Add tests covering the reported issue (implicitly casting Enum to custom struct expecting int) and ensuring Enum-to-Boolean logic remains intact without extra (long) casts. Co-authored-by: GrahamTheCoder <2490482+GrahamTheCoder@users.noreply.github.com>
- Update TypeConversionAnalyzer to only use EnumCastThenConversion if the target type is not an Enum and does not have a defined Conversions.To method. - Add tests covering the reported issue (implicitly casting Enum to custom struct expecting int) and ensuring Enum-to-Boolean logic remains intact without extra (long) casts. Co-authored-by: GrahamTheCoder <2490482+GrahamTheCoder@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes an issue where implicitly assigning/comparing an enum value to a custom C# type via an implicit widening conversion operator failed to generate the necessary intermediate cast to the enum's underlying integer type (yielding
(MyType)MyEnum.Valuewhich causes CS0030 instead of(MyType)(int)MyEnum.Value).PR created automatically by Jules for task 4501922553304845946 started by @GrahamTheCoder
Gemini
I have reviewed the changes in this pull request. The modification in
TypeConversionAnalyzer.csadjusts the logic for enum conversions to handle a wider range of target types by introducing an intermediate cast to the enum's underlying type. The new test inExpressionTests.csvalidates this change for a custom struct with an implicit conversion operator. The changes appear to correctly address the described issue, and I have no further recommendations for improvement.