-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add nullability info field into discard expression #66309
Conversation
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Show resolved
Hide 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.
Done with review pass (iteration 2)
I added an indicator if the user defined type of discard expression argument( |
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
As Rikki pointed out, I read the flag in reverse :-/
Done with fixing the review pass |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
@@ -377,7 +377,7 @@ private BoundExpression SetInferredType(BoundExpression expression, TypeSymbol t | |||
{ | |||
var pending = (BoundDiscardExpression)expression; | |||
Debug.Assert((object?)pending.Type == null); | |||
return pending.SetInferredTypeWithAnnotations(TypeWithAnnotations.Create(type)); | |||
return pending.SetInferredTypeWithAnnotations(TypeWithAnnotations.Create(true, type, true)); |
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 wasn't clear to me why we don't just want to call TypeWithAnnotations.Create(type)
here. An oblivious annotation seems fine here, just as we have on DeconstructionVariablePendingInference
above.
}); | ||
} | ||
|
||
private static void checkDiscard(SemanticModel model, DiscardDesignationSyntax discard, string type) { |
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.
Consider renaming these to CheckDiscard
to match conventions elsewhere in the project.
var comp = CreateCompilation(source, targetFramework: TargetFramework.Net70); | ||
comp.VerifyDiagnostics(new[] { | ||
// (25,77): warning CS8601: Possible null reference assignment. | ||
// static void TestA<T>(IOperation<T> operation, out T result) => result = default; |
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.
Consider assigning default!
or similar since these warnings aren't really the interesting part of the test.
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.
Done review pass. Looking in good shape to me, just a few small things to address.
Done with fixing review pass |
src/Compilers/CSharp/Test/Semantic/Semantics/MethodTypeInferenceTests.cs
Outdated
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
@jcouv for a second review |
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 Thanks (iteration 10)
Thanks for the contribution @TomatorCZ! |
Regards the issue and PR.
Problem
Different behavior of discard expression and local variable in out arguments during inferring type argument of generic method.
Reason
BoundDiscardExpression
doesn't contain information about nullability resulting in losing information about it between binding and the inference. See code.Solution
I added field holding examined nullability info.