Preserve nullable typing for ignored null-conditional access in coalesce expressions#212
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix null coalesce operator in GetCost method
Preserve nullable typing for ignored null-conditional access in coalesce expressions
May 28, 2026
PhenX
marked this pull request as ready for review
May 28, 2026 16:09
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the generator’s null-conditional ignore rewrite so nullable value typing is preserved for simple ?? left operands, preventing invalid generated expressions like decimal ?? decimal.
Changes:
- Adds nullable cast emission when an ignored conditional access feeds directly into a coalesce expression.
- Adds a regression generator test and verified snapshot for
Price?.Amount ?? 0m.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/EntityFrameworkCore.Projectables.Generator/SyntaxRewriters/ExpressionSyntaxRewriter.NullConditionalRewrite.cs |
Adds coalesce-left detection and nullable cast generation for ignored null-conditional access. |
tests/EntityFrameworkCore.Projectables.Generator.Tests/NullableTests.cs |
Adds regression coverage for ignored null-conditional access with ??. |
tests/EntityFrameworkCore.Projectables.Generator.Tests/NullableTests.NullConditionalNullCoalesceTypeConversion_WithIgnoreSupport.verified.txt |
Adds the expected generated expression snapshot. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
github-merge-queue Bot
pushed a commit
to DFE-Digital/teaching-record-system
that referenced
this pull request
Jul 22, 2026
Updated [EntityFrameworkCore.Projectables](https://github.com/EFNext/EntityFrameworkCore.Projectables) from 6.0.4 to 6.0.6. <details> <summary>Release notes</summary> _Sourced from [EntityFrameworkCore.Projectables's releases](https://github.com/EFNext/EntityFrameworkCore.Projectables/releases)._ ## 6.0.6 ## What's Changed * Preserve nullable typing for ignored null-conditional access in coalesce expressions by @PhenX with @Copilot in EFNext/EntityFrameworkCore.Projectables#212 * Fix duplicate joins when materializing writable projectables with includes by @PhenX in EFNext/EntityFrameworkCore.Projectables#218 **Full Changelog**: EFNext/EntityFrameworkCore.Projectables@v6.0.5...v6.0.6 ## 6.0.5 ## What's Changed * Fix source generator crash when parameter type uses verbatim @ keyword prefix by @Copilot in EFNext/EntityFrameworkCore.Projectables#208 **Full Changelog**: EFNext/EntityFrameworkCore.Projectables@v6.0.4...v6.0.5 Commits viewable in [compare view](EFNext/EntityFrameworkCore.Projectables@v6.0.4...v6.0.6). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: James Gunn <james@gunn.io>
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.
NullConditionalRewriteSupport.Ignorecurrently strips?.to direct member access, which breaks??when the left side was originally nullable (e.g.Price?.Amount ?? 0mbecomingPrice.Amount ?? 0m). This causes invalid generated code (decimal ?? decimal).Generator fix: typed rewrite for
??left operandExpressionSyntaxRewriternull-conditional ignore path to detect when a conditional access is the left operand of a coalesce.Nullable<T>and the rewritten member/index access isT, the generator now emits an explicit cast toNullable<T>.Scope control
Regression coverage
NullConditionalNullCoalesceTypeConversion_WithIgnoreSupportinNullableTests.