Skip to content

Fix LINQ extension methods conversion to C##1226

Merged
GrahamTheCoder merged 1 commit intoicsharpcode:masterfrom
GrahamTheCoder:fix-linq-extension-methods-expansion-17340425955327495994
Mar 11, 2026
Merged

Fix LINQ extension methods conversion to C##1226
GrahamTheCoder merged 1 commit intoicsharpcode:masterfrom
GrahamTheCoder:fix-linq-extension-methods-expansion-17340425955327495994

Conversation

@GrahamTheCoder
Copy link
Member

Fixes issue where LINQ extension methods are incorrectly replaced with static Enumerable methods when converted from VB to C# (Issue #1149). This occurred because non-generic extension methods (like Sum or Max on int enumerables) 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 VbNameExpander guard 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 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.

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>
@GrahamTheCoder GrahamTheCoder marked this pull request as ready for review March 10, 2026 23:29
@GrahamTheCoder GrahamTheCoder merged commit 708eec7 into icsharpcode:master Mar 11, 2026
3 checks passed
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.

1 participant