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
Set null state on dereference #30564
Conversation
@dotnet/roslyn-compiler please review. |
@dotnet/roslyn-compiler, please review. This change prevents redundant (and incorrect) warnings on subsequent dereferences of the same variable. The actual code change is small - most of the changes are to the tests. |
@gafter is added to the review. #Closed |
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.
It feels incorrect to mark Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:1357 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
It feels incorrect to mark Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:1946 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
It feels incorrect to mark Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:3679 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
If this node can be a part of dynamic invocation, it feels incorrect to mark Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:4185 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
It feels incorrect to mark Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:4213 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
It feels incorrect to mark Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:4301 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
If this is a target of an assignment, is receiver actually going to be checked before the value (right hand side) is evaluated? Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:453 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
Similar question here Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:459 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
It would be good to have a clear understanding what constructs go through here Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:3671 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
It would be good to have a clear understanding what constructs go through here Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:3665 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
If this is a target of an assignment, is receiver actually going to be checked before the value (right hand side) is evaluated? #Pending Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:447 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
It would be good to have a clear understanding what constructs go through here Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:3690 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
Done with review pass (iteration 2). Tests are not looked at. #Closed |
@dotnet-bot retest this please |
Good catch. In these cases, we're reporting one warning dereferencing the variable, but not reporting the same warning for other dereferences within the same expression. Logged ##30598 and added test In reply to: 431103720 [](ancestors = 431103720) Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:1357 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
The comment probably should be adjusted #Closed Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:9864 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
Here too #Closed Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:9900 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
And here #Closed Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:9936 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
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.
LGTM (iteration 3), identified issues can be followed up on later.
Added tests and added comment to In reply to: 431108827 [](ancestors = 431108827) Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:447 in cf7548d. [](commit_id = cf7548d58a41cf652d841bfea163dcbd21081a6d, deletion_comment = False) |
@AlekseyTs, all comments have been addressed. Thanks. |
@jaredpar for approval |
approved to merge |
@cston Do we have a test covering this behavior? void Method(object? obj)
{
obj.Extension(); // Should not warn
obj.ToString(); // Should warn
}
static void Extension(this object? obj) { } |
@sharwell, there are a couple of tests with extension methods (see |
Fixes #23270.