Repository navigation
VB to C#: Rewrite query syntax conversion around range variable scope - #1305
Merged
GrahamTheCoder merged 45 commits intoNov 9, 2026
Merged
GrahamTheCoder merged 45 commits into
GrahamTheCoder merged 45 commits into
Conversation
Introduce a new query converter that walks VB query clauses left to right, tracking which VB range variables are in scope and the C# expression for each, rather than splitting the query into segments up front. - Range variable references are substituted by symbol, so a VB Select that isn't the last clause no longer needs a continuation: names are reused where possible, renamed on clashes, and the implicit final select is built from VB's scope (fixes icsharpcode#1163, icsharpcode#1172). - Values that can be inlined without changing evaluation count are substituted, otherwise a let clause is introduced. - Distinct/Skip/Take/Skip While/Take While materialize the current element and continue the query from the method call. Queries using Join, Group Join, Group By or Aggregate still go through the legacy converter for now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
- The inner side of each join condition is found from the range variable symbols it references, rather than the syntax of the left hand side, so any expression works on either side (fixes icsharpcode#936). - Group Join aggregates become method calls on the join...into variable, which is named after the `Group` aggregation where present, so `Into Group` no longer throws (fixes icsharpcode#935). - Joins nested within a Join are flattened, attaching each condition to the earliest join where everything it references is in scope. - Queries ending without a Select now return all VB range variables in scope (fixes icsharpcode#931), and Order By after Select works (fixes icsharpcode#1016). - Inlined values keep their source mapping when used immediately, so comments stay in order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
After a VB Group By the range variables in scope are its keys and aggregations, so each is expressed in terms of the C# continuation variable: keys as `g.Key`/`g.Key.Name`, aggregations as method calls on the group with a lambda over the group's element. - Multiple keys no longer throw (fixes icsharpcode#1014, icsharpcode#298), and aggregations are no longer dropped (fixes icsharpcode#1272, icsharpcode#867). - Key references are rewritten, e.g. Order By after Group By (fixes icsharpcode#948), and named groups keep their name (icsharpcode#1180). - Group items and compound elements (several range variables in scope) become anonymous types, with aggregate lambdas reading their members. - An inferred anonymous type member keeps VB's name when the converted expression would infer a different one, e.g. after substitution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
- An initial Aggregate becomes method calls on the (possibly filtered) source. With several aggregations the result is an anonymous type, and the source is only repeated if that's cheap, otherwise it's evaluated once like VB does. - Aggregate within a query adds a range variable per aggregation over a nested query, with the nested query held in a group variable when it's used by several aggregations, mirroring VB's translation. - Nested queries know their enclosing query's range variables, so generated names don't clash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Every VB query clause is now handled by the scope-tracking converter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
- `From x As T In xs` uses C#'s typed from (Cast<T>) only for reference conversions, where it behaves the same as VB's CType. Other conversions (e.g. numeric widening, which Cast<T> would throw for) select the converted value instead. - Non-generic sources (e.g. ArrayList), which VB implicitly casts to Object, get an explicitly typed from clause as C# requires. - Self-verifying tests run each VB query and its conversion and compare the results, covering every clause kind and the reported issues. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Comparisons within queries are deliberately kept simple so that providers like EF can translate them from expression trees. But for a query that runs as delegates, dropping Option Compare Text changed which strings matched. The VB compiler's translation of the query shows whether its lambdas are expression trees, so case-insensitive equality is now kept for queries that aren't, consistent with how lambdas are already converted. Query operators themselves (Group By, Distinct, Join, Order By) aren't affected by Option Compare in VB, which the new self-verifying tests confirm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Covers VB and C# query semantics (from the Roslyn binders and verified by running VB), why the previous converter needed a special case per issue, the scope-tracking model, inline vs let rules, naming, the progressive fallback order, Option Compare Text, and known limitations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
- Substituted expressions can reference C# range variables VB has dropped, so they're no longer substituted where a later lambda parameter of the same name would capture them, and generated lambda parameters don't reuse such names. Previously e.g. `Select y = x Where ys.Any(Function(x) x > y)` silently compared x with itself. - Generated names avoid names declared within the query and enclosing lambda parameters. - `Join c As T In xs` keeps its type, like From. - Only compiler generated operator calls decide whether a query is an expression tree, so a user's IQueryable lambda inside a LINQ to objects query doesn't lose Option Compare Text; a query nested in an expression tree is treated as part of it. - An explicit identity Select is kept, since it changes the result type. - A query resumed after a method call selects its from variable rather than rebuilding an identical anonymous type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Pure refactor: join planning returns the conditions for each join (or null when they can't be flattened), and conditions/aggregations work with the joined element (one or more range variables) rather than a single variable, ready for joining against a subquery. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
VB allows joins nested within a Join or Group Join. Flattening them into a sequence of C# joins only works for inner joins whose conditions each use one joined variable on the inner side, so previously a Group Join among them threw, a nested Join within a Group Join threw, and a condition like `On x Equals y + z` produced C# that didn't compile. Those cases now mirror VB's own translation (`xs.Join(ys.Join(zs, ...))`): the joined variable and its nested joins become a subquery, joined as one compound C# variable whose members the VB variables refer to. Flattenable joins are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
The VB parser rejects them (BC30205) and the VB binder asserts they never occur, so this isn't a conversion limitation. The guard stays for code with errors, rather than silently dropping clauses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Pure refactor: - Split QueryClauseConverter into partial files for joins, grouping and substitution rules. - Rename to describe intent, e.g. Define -> DefineVariable(canSubstitute, keepSourceMapping), IsMethodBoundary -> IsConvertedToMethodCall, EnsureQuery -> EnsureQueryOpen, and extract helpers such as EvaluateOnce, CallCast, SelectConverted and UsesSimplifiedQueryComparison. - Trim doc comments to the reasons the code can't show. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…entation States the VB and C# rules (with sources) that the conversion relies on, and where the implementation meets each, without historical context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Pure refactor. Parts with a self-contained responsibility now have their own class: - SubstitutionRules: whether a value can be substituted for its variable - FlatJoinPlanner: whether nested joins can be written as flat C# joins - QuerySourceConverter: making VB's implicit AsEnumerable/Cast/CType on a range variable's collection explicit Join and grouping conversion stay as partials of QueryClauseConverter, since they recursively convert nested clauses and share its variable registration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Coverage and Stryker.NET mutation testing over the query conversion code showed paths no test exercised, including: - builder state across several continuations (two Group Bys), method calls after a continuation, and a method call right before the final Select - nested joins only unflattenable once both variables are in scope - substitution not being blocked by unrelated or earlier lambda parameters, or member names - generated names avoiding element members and enclosing queries - expression tree and query flags being combined for nested queries and restored afterwards - typed From over a non-generic source Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Pure refactor: AddFrom no longer special-cases the first clause, and an argument and fallback that made no difference to any valid query are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Covers names generated in a nested query avoiding C#-only names in the enclosing query, two join subqueries in one query, a typed Group Join variable, and a typed From whose variable isn't called x. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Pure refactor: - The builder no longer reopens the query in each method: the converter already opens it before each clause, as EnsureQueryOpen documents. - The generated select before a method call no longer needs line mapping. - Range variables are no longer unregistered after a query, since their symbols can't occur elsewhere. - A redundant element name check and null filter are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
VB evaluates a Let or mid-query Select value once for each element reaching that clause. Substituting it past a Where, Order By, Skip/Take etc. changed which elements it ran for and in what order, and an unused value was dropped entirely, so side effects and exceptions differed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Roslyn's formatter puts two line breaks after a `}` separated from the next
token only by elastic trivia, e.g. `from x in new[] { 1 } where ...` written
on one VB line.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…fferently Found by blind review: * A dropped range variable could be captured by a local or loop variable in a later lambda, and a referenced field by a later range variable of the same name. * A value substituted into a conditional operand of the final Select was only evaluated on one branch. * An unnamed mid-query Select was always substituted, even past a filter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
C# infers a single join key's type from both sides, but anonymous composite key members must match exactly, e.g. Integer and Integer? (CS1941). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…dexing
`$"{y}"` with a substituted conditional, and `a(0)` with a substituted
`New Integer(x) {}`, didn't compile when the output was parsed as text.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
A Func lambda in an IQueryable query (`o.Items.Any(Function(i) i.S = s)`) is still translated by the provider, so its comparisons stay simplified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…ut of queries Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…r evaluation Found by blind review: * A value dropped by a later mid-query Select was never evaluated. * Substituting into the final Select could evaluate values out of declaration order, or after a call the Select makes first. * A substituted lambda was invoked directly (CS0149), and couldn't be a let without a delegate type (CS1932). * A range variable's As type and a Nothing value's type were lost (CS1061, CS0828). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
An Aggregate over an IQueryable inside a LINQ to objects query made the whole query look like an expression tree, losing Option Compare Text equality. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
`Where b` with `b As Boolean?` didn't compile (CS0266); VB treats Nothing as False. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…condition to Boolean The lambda is applied to the query's result, where the query's own range variables aren't in scope, so `x` needn't become `x1`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…ntext Where only whether a condition is True matters, VB treats Nothing like False. C#'s lifted relational operators are false when an operand is null, as is its lifted == unless both operands are null, so `If n = 1` can be `if (n == 1)`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
Only queries compiled to expression trees (e.g. IQueryable for EF) keep plain C# comparisons, since the provider decides their semantics and may not translate VB's runtime helpers or C# patterns (icsharpcode#316, icsharpcode#894). A query compiled to delegates is just code, so `Where x = s` now treats Nothing like "" as VB does. That makes in-query handling the same as expression tree handling, so the two query tracker flags become one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…ery value substitution Found by blind review: * `Select a = G, b = y` called G before evaluating the substituted y, since a VB call without parentheses looks like a name. * `NameOf(y)` of a substituted range variable became `nameof(x + 1)`, or "Key" for a group key, and counted as the value's only evaluation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
* A query of only `From x In list` became `list`, changing its type. * An implicit AsEnumerable wasn't parenthesized, or emitted at all for an instance method. * An Aggregate nested in an Aggregate crashed the expression tree check. * `Let f As Predicate(Of Integer) = Function(a) ...` was wrapped twice as a Func. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…rElse in expression trees `Take While b` with `b As Boolean?` cast to bool and threw on Nothing, and `Where b AndAlso x` in an IQueryable query didn't compile (CS0019). Providers translate `b == true`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…hare range variable naming Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…ion predicates Found by blind review: * `n = 1 AndAlso Check` skipped calling Check when n was Nothing, since a VB call without parentheses looks like a name. * `Into Count(n > 1)` over Integer? didn't compile; VB converts the predicate to Boolean (throwing for Nothing). * An already-bool lifted comparison got a redundant `== true` in expression trees. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…e NameOf of a member Found by blind review: * `Let a = F(x) Let b = G(x) Select a` evaluated G first, since b stayed a let while a moved to the final select. * `NameOf(a.Member)` of a substituted range variable didn't compile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
`If n = 1 AndAlso 1 \ z = 0` evaluates the division in VB even when n is Nothing, so the left can only become a lifted operator if the right is free of arithmetic, narrowing conversions and user-defined operators as well as calls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…d and delegate types Found by blind review: * A Let within an Aggregate clause was substituted past its Where/Order By, since the rules only looked at the outer query's clauses. * A cheap value like a local was substituted into a lambda or nested query in the final Select, so read later than VB reads it. * `From x As Object In ints` and `Let o As Integer? = x` lost the declared type. * `Let f As Func(Of Integer) = AddressOf Five` didn't compile. Also substitutes a single-use value into a Where, Let or first Order By key where that keeps VB's evaluation, e.g. `Into Count() Where Count > 1`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…y what they hold Found by blind review: * Order By reads every element before evaluating any key, so a value substituted into it ran after earlier lets for all elements (or not at all for Count()). * `Let d = y` where y was substituted with a call, or a field, counted as cheap or unchanging, reordering evaluation or reading the field too late. * A Group By item can hold a lazy nested query, so reads a value as late as a Let. * An anonymous type member name looked like a name a later range variable shadows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…son semantics A provider is passed the first source, a join's inner source and Skip/Take counts as values, so they're ordinary code rather than part of the expression tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
… convert Skip/Take counts Found by a review guided by mutation testing and coverage: * An Aggregate clause's source runs within the enclosing query's lambda (or as ordinary code for an initial Aggregate), so takes its semantics from there, not from the whole query. * `Skip n` with a Long, or `Take 1.5`, didn't compile; VB converts to Integer. * A named range variable was also registered as a plain declaration, keeping a needless let. Also adds tests for gaps the mutation run found. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
…d correct README examples Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G
1 task done
GrahamTheCoder
added a commit
that referenced
this pull request
Nov 9, 2026
Added note about Linq query conversion changes in pull request #1305.
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.
Line changes: Production: +1444, -495. Test: +3212, -106. Md files: +98
Fixes the "Difficult area" LINQ query syntax issues (VB -> C#); each has a regression test:
Selectis followed byWhere#1163Problem
The old
QueryConvertersplit VB clauses into segments up front and converted clause syntax one-to-one, adding special cases as issues arrived. Almost every reported bug has the same root cause: VB and C# disagree about which range variables are in scope after each clause (VBSelectandGroup Byreplace the scope, C# can only drop variables withinto), and about what a query returns without a finalSelect(VB returns an anonymous type of all range variables in scope). Clause-by-clause syntax can't express either, so each new combination needed another patch.Documentation:
CodeConverter/CSharp/Queries/README.md. It sets out the VB and C# rules the conversion relies on (with sources: Roslyn's query binders and the language docs, plus running VB) and where the implementation meets each.Solution
Classes in
CodeConverter/CSharp/Queries:QueryClauseConverterconverts VB clauses left to right into aCsQueryBuilder. The joins and grouping parts are partials, because they recursively convert nested clauses.CsQueryBuildertracks the VB scope (which alone decides the element) and the C# expression currently evaluating each VB range variable (x,g.Key.P1,g.Sum(t => t.A),e.xafter a method call, ...).SubstitutionRulesdecides when a value can be substituted rather than declared withlet, for the clauses of the (sub)query being built.FlatJoinPlannerdecides whether nested joins can be flat C# joins.QuerySourceConvertermakes VB's implicitAsEnumerable/Cast/CTypeon a source explicit.ExpressionTreeDetectorreads VB's own translation (ITranslatedQueryOperation) to tell whether a query compiles to delegates or to expression trees.RangeVariableReplacementsis keyed by range variable symbol and consulted inConvertIdentifierNameAsync, so every reference (including inside nested lambdas and queries) is substituted. The VB binder handles shadowing, case-insensitivity and nested queries.What the conversion does:
Selectbecomeslets or substitutions (renaming on clashes),Group Bybecomesgroup ... into gwith keys and aggregations expressed viag, andJoinsides are chosen by the symbols each side references.let, typed where C# can't infer it (Astypes,Nothing, delegates).xs.Join(ys.Join(zs, ...)).let, then continuation, then a method call with a resumedfrom, then a join subquery, thenNotImplementedException(a compile error comment) for anything unrepresentable.Comparisons (per review discussion)
Nothing = "", Option Compare Text, and nullable logic. Previously every query was simplified, which gave different results for null strings, nullables and Option Compare Text.=(one nullable side) and for</>/<=/>=, so those are plain:where e.N == 123,where e.N > 1 && (e.S ?? "") == (s ?? "").<>and both-nullable=need a pattern.If/Where/Skip/Take Whileand the operands ofAndAlso/OrElsewithin them. It excludes the left ofAndAlsowhen the right could throw or have side effects, since VB evaluates the right even when the left is Nothing.Ifstatements outside queries, e.g.if (status == PasswordStatus.Locked)instead ofif (status.HasValue && status.Value == PasswordStatus.Locked), with the same behaviour.IQueryable, e.g. EF): plain C# operators (x == s,b == truefor aBoolean?operand of&&), which the provider translates. This is the case behind VB -> C# System.Linq.Expression needs special treatment #316 and VB -> C#: wrong conversion of linq expression containing nullable value #894: the provider decides the semantics (e.g. collation), and it may not translate VB's runtime helpers or C# patterns.Skip/Takecounts, including those of anAggregateclause within a delegate query.IQueryableevaluated in memory (e.g.list.AsQueryable(), or client-side evaluation) runs the plain C# comparisons, so it differs from VB forNothing = "", nullables and Option Compare Text.Objectcomparisons and relational string comparisons still emit VB runtime helpers even in expression trees.Blind reviews
Fresh reviewers, with no anchoring on earlier results, did 7 rounds of review. Each verified its findings by running them. Every real finding has a regression test (mostly self-verifying runtime tests) and a fix.
Select, unnamedSelectpast a filter, composite join keys of different types, text-only parenthesization, and aFunclambda inside an expression tree.Select, evaluation order in the finalSelect, lambda values,AggregateoverIQueryablemisdetected as an expression tree, and older bugs:Astypes,Nothing,WhereonBoolean?.NameOf,Take WhileonBoolean?, a bareFrom x In listchanging type, implicitAsEnumerable, nestedAggregate, delegate-typedLet, andBoolean?AndAlsoin expression trees.letvalue evaluated before an earlier substituted one, VB calls without parentheses on the right ofAndAlso,Boolean?aggregation predicates, and a redundant== true.Letinside anAggregatemoved past itsWhere, cheap locals read later inside lambdas,AndAlsowith a throwing right side, boxing/nullableAstypes,AddressOf; pluswhere Group.Count() > 1for single-use aggregations.Order By, the first fix to flip-flop, becauseOrderByreads every element before evaluating any key. Also: range variables judged by what's substituted for them,Group Byitems holding lazy queries, and the in-memory parts ofIQueryablequeries.Aggregateclauses' in-memory/expression-tree boundary,Skip/Takecounts converted toInteger, and a duplicate declaration. It also added tests for mutation and coverage gaps and removed two conditions that can't change the result.Stopping point: round 6 flip-flopped on
Order By, and round 7's remaining bugs were narrow (theIQueryable/Aggregateboundary). The loop stops here, though another round is easy to run.Declined, as not worth the code:
ByRef;Boolean?bodies;Limitations (also in the README):
Values cheap to repeat (names, member accesses, literals) are substituted, so a property getter with side effects could run a different number of times. Getters, and member access on a possibly-null receiver, are also assumed not to throw on the right of
AndAlso.Operators before a substituted value in the same clause are assumed not to throw.
Tests:
LinqQueryScopeTests,LinqQueryJoinTests,LinqQueryGroupByTestsandLinqQueryAggregateTests, plus more inLinqExpressionTests.csandBinaryExpressionTests.cs.LinqExpressionTests.vb,LinqEvaluationTests.vb,LinqComparisonTests.vb,LinqOptionCompareTextTests.vb) run each VB query and its C# conversion and compare the results. Many log the order in which values are evaluated.Locally on Linux, the suite has the same failures as
master(line-ending/solution-file/enum-rounding tests that already fail there) and no new ones.Process
🤖 Generated with Claude Code
https://claude.ai/code/session_019FEr8GSsdfh4WNGNkwrb9G