Analyze throw expression and adjust analysis of null-coalescing operator#32991
Analyze throw expression and adjust analysis of null-coalescing operator#32991jcouv merged 12 commits intodotnet:masterfrom
Conversation
There was a problem hiding this comment.
Consider adding a ref LocalState state parameter. #Closed
There was a problem hiding this comment.
var rightState = this.State.Clone(); [](start = 12, length = 36)
Why do we need this clone? Is LearnFromNonNullTest changing the current state? Also, the rightState name is somewhat misleading, we haven't visited the right side yet, which is not in line with the naming pattern used in this component. #Closed
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
warning CS8602: Possible dereference of a null reference. [](start = 27, length = 57)
The warning feels misleading, e is not dereferenced here. #Closed
|
Done with review pass (iteration 1) #Closed |
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
node.Kind == BoundKind.ThrowExpression || [](start = 25, length = 42)
Relaxing this assert doesn't feel like a right thing to do. Are we not setting _resultType properly for a throw expression? I think we should do that instead. #Closed
There was a problem hiding this comment.
What do you think the _resultType should be?
Currently, we let _resultType be Exception (or whatever is thrown) from visiting the thrown value.
If we wanted to set it properly, it should probably be the converted type of the throw expression, which does not exist in the throw expression itself, only in the conversion that wraps the throw expression.
A possibility is to set the _resultType to null/default, since the BoundThrowExpression has a null Type. Then I would adjust this method to handle null/default _resultType, instead of special-casing throw expression.
Do you think that's better?
There was a problem hiding this comment.
Do you think that's better?
In this visitor, after visiting each expression, we should set _resultType the result type should reflect the original type of the node plus added nullability information. It shouldn't matter if there is a conversion on top of the BoundThrowExpression node, it will be handled when its turn comes and the _resultType will be adjusted for it as appropriate. That said, there should be no special handling/treatment for BoundThrowExpression, but adjusting the assert adds it.
In reply to: 253510940 [](ancestors = 253510940)
|
Done with review pass (iteration 2) #Closed |
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Consider adding a test for string~. #Closed
|
Done review pass (commit 3). #Closed |
Revert Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:1790 in 36c319f. [](commit_id = 36c319fd8e756ea6e9e0e4e5919651d92c523b33, deletion_comment = False) |
|
Done review pass (commit 8) |
Indeed. Thanks
This one is fine. Getting an extra warning on the |
333fred
left a comment
There was a problem hiding this comment.
LGTM (commit 9). Comment about string~ in ThrowExpressionInNullCoalescingOperator still needs to be addressed, but that can just be added to the linked bug as a note.
|
Thanks all for your feedback and patience. |
|
@jcouv master is 16.1 now. |
x ?? y, we should learn thatx != null.Fixes #32879