Fix LINQ extension methods conversion to C##1226
Merged
GrahamTheCoder merged 1 commit intoicsharpcode:masterfrom Mar 11, 2026
Merged
Conversation
Updates `VbNameExpander` to correctly bypass syntax expansion for all extension methods (both generic and reduced, such as `.Sum()` over numeric collections). Previously, non-generic extension methods were expanded to static calls (e.g. `Enumerable.Sum(...)`), which the C# simplifier phase couldn't contract back to fluent syntax, leading to erroneous or uncompilable C# output. Renames `IsOriginalSymbolGenericMethod` to `IsOriginalSymbolGenericOrExtensionMethod` to reflect its behavior of handling `IsExtensionMethod` and `MethodKind.ReducedExtension`. Includes a new reproducing unit test `LinqExtensionMethodReproTests` to ensure continued functionality. 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 issue where LINQ extension methods are incorrectly replaced with static
Enumerablemethods when converted from VB to C# (Issue #1149). This occurred because non-generic extension methods (likeSumorMaxonintenumerables) were mistakenly bypassing a guard clause and expanding into full static method invocations during the VB syntax expansion step. The C# simplifier was subsequently failing to reduce them back.By updating the
VbNameExpanderguard clause to cover all extension methods and reduced extension methods, the idiomatic fluent syntax is successfully preserved.Included unit test verified against numeric collections
Select().Sum(),OrderBy().Max(),Select().Count(), etc.PR created automatically by Jules for task 17340425955327495994 started by @GrahamTheCoder
--
Updates
VbNameExpanderto correctly bypass syntax expansion for all extension methods (both generic and reduced, such as.Sum()over numeric collections). Previously, non-generic extension methods were expanded to static calls (e.g.Enumerable.Sum(...)), which the C# simplifier phase couldn't contract back to fluent syntax, leading to erroneous or uncompilable C# output.Renames
IsOriginalSymbolGenericMethodtoIsOriginalSymbolGenericOrExtensionMethodto reflect its behavior of handlingIsExtensionMethodandMethodKind.ReducedExtension.Includes a new reproducing unit test
LinqExtensionMethodReproTeststo ensure continued functionality.