Skip to content

Fix enum conversion bug #1212#1228

Draft
GrahamTheCoder wants to merge 3 commits intoicsharpcode:masterfrom
GrahamTheCoder:fix-enum-conversion-bug-4501922553304845946
Draft

Fix enum conversion bug #1212#1228
GrahamTheCoder wants to merge 3 commits intoicsharpcode:masterfrom
GrahamTheCoder:fix-enum-conversion-bug-4501922553304845946

Conversation

@GrahamTheCoder
Copy link
Member

@GrahamTheCoder GrahamTheCoder commented Mar 10, 2026

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.Value which 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.cs adjusts 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 in ExpressionTests.cs validates 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.

google-labs-jules bot and others added 3 commits March 8, 2026 09:26
- 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>
@GrahamTheCoder GrahamTheCoder changed the title Fix enum conversion bug 4501922553304845946 Fix enum conversion bug #1212 Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VB -> C#: Enum Values as Integer

1 participant