Skip to content

Keep null-conditional LINQ chains in method syntax - #3969

Open
sailro wants to merge 1 commit into
icsharpcode:masterfrom
sailro:fix-null-conditional-query-syntax
Open

Keep null-conditional LINQ chains in method syntax#3969
sailro wants to merge 1 commit into
icsharpcode:masterfrom
sailro:fix-null-conditional-query-syntax

Conversation

@sailro

@sailro sailro commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

tl;dr: Keep LINQ method syntax when its receiver chain contains a null-conditional access.

Fixes #3968

Problem

IntroduceQueryExpressions only checks the immediate LINQ receiver for ?.. A chained Where(...).Select(...) can therefore be converted to query syntax even when its source contains a null-conditional access over a value type.

The query source is then nullable and does not implement the query pattern.

Solution

Make IsNullConditional inspect the member and invocation receiver chain before introducing query syntax.

  • At least one test covering the code changed

Query syntax cannot preserve a null-conditional receiver that lifts a value type. Detect null conditionals through the LINQ receiver chain before introducing query syntax.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0dd407b6-9410-48df-add5-761ca4a8dec0
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.

Null-conditional LINQ chain over a value type is emitted as invalid query syntax (CS1936)

1 participant