-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C# 14: Null conditional assignments. #21158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
michaelnebel
wants to merge
13
commits into
github:main
Choose a base branch
from
michaelnebel:csharp/cfgforaccess
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,405
−218
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9894993
C#: Add CFG support for null conditional assignments and include eg. …
michaelnebel b061c4d
C#: Update test expected output.
michaelnebel 0bf0cba
C#: Add some null conditional assignments CFG tests.
michaelnebel 4ba8923
C#: Update test expected output.
michaelnebel f0135e9
C#: Add a tests for MaybeNullExpr.
michaelnebel 5942edf
C#: Take null conditional assignments into account in MaybeNullExpr.
michaelnebel ab432ec
C#: Update test expected output.
michaelnebel 812fdbe
C#: Add change-note.
michaelnebel 3d988e8
C#: Add field access for out assignments in the CFG.
michaelnebel bd1c6e6
C#: Exclude the field access cases from missing argument call.
michaelnebel 86198e3
C#: Add tests for out writeacceses.
michaelnebel beb7750
C#: Address review comments.
michaelnebel 33fc2ba
C#: Update test expected output.
michaelnebel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
csharp/ql/lib/change-notes/2026-01-14-null-conditional-assignments.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * C# 14: Support for null-conditional assignments (such as `c?.Prop = p`). Furthermore, the `MaybeNullExpr` class now takes null-conditional access (such as `?.`) into account when modeling potential null values. |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually needed? I would think that an expression like
x?.M()can always potentially benull, regardless of what we know aboutx.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if
xis variable (or other stuff that is not special cased in theMaybeNullExprclass), but it appears we need to propgate the maybe null information for casts and conditionals (stuff that is explicitly handled in theMaybeNullExprclass itself). That is, to properly handle(x as C).GetInt().An example of an extra finding: https://github.com/dotnet/roslyn/blob/6afbfb45ccc9691167206bf29482a99b1d6d469c/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs#L24398
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant was why not
That should give us strictly more results, and I would assume that any
x?.M()expression can be potentiallynullbecause it is conditionally qualified.