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
Infer null state from is object
and is { }
tests
#40892
Changes from 2 commits
7883a31
eb187d5
666f3a8
1d6b4e3
2eb10b4
85343e7
9a27143
1534256
1fd3753
0929381
04ead25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,6 @@ public override BoundNode VisitITuplePattern(BoundITuplePattern node) | |
/// </summary> | ||
/// <param name="inputType">Type type of the input expression (before nullable analysis). | ||
/// Used to determine which types can contain null.</param> | ||
/// <returns>true if there is a top-level explicit null check</returns> | ||
private void LearnFromAnyNullPatterns( | ||
int inputSlot, | ||
TypeSymbol inputType, | ||
|
@@ -352,6 +351,11 @@ protected override void VisitSwitchSection(BoundSwitchSection node, bool isLastS | |
if (inputSlot > 0) | ||
{ | ||
MarkDependentSlotsNotNull(inputSlot, inputType, ref this.StateWhenFalse); | ||
if (t.Syntax is RecursivePatternSyntax { Type: null, Designation: null, PositionalPatternClause: null } syntax && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It is not correct to check the syntax. See https://github.com/dotnet/roslyn/blob/master/docs/compilers/Design/Bound%20Node%20Design.md#bound-nodes-should-capture-all-semantic-information-embedded-in-the-syntax Instead this should be based on the node. It may be necessary to introduce a "BoundDagExplicitNonNullTest" just like we have an explicit and non-explicit null test. Alternatively, add a |
||
syntax.PropertyPatternClause?.Subpatterns.Count == 0) | ||
{ | ||
LearnFromNullTest(inputSlot, inputType, ref this.StateWhenFalse, markDependentSlotsNotNull: false); | ||
} | ||
learnFromNonNullTest(inputSlot, ref this.StateWhenTrue); | ||
} | ||
gotoNode(p.WhenTrue, this.StateWhenTrue, nodeBelievedReachable); | ||
|
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.
This will have to be modified to look for bound patterns that are explicit non-null tests. Probably adjust the name of this method as well. #Resolved
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.
Added.
In reply to: 365461994 [](ancestors = 365461994)