-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Address various minor param-nullchecking issues #58321
Address various minor param-nullchecking issues #58321
Conversation
IL_0002: newobj ""C.<GetChars>d__0..ctor(int)"" | ||
IL_0007: ldarg.1 | ||
IL_0008: ldstr ""s"" | ||
IL_000d: call ""ThrowIfNull"" |
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.
I was a bit surprised to see us create the state machine then do the null
check. Given that we do the null
check before calling base / this
ctor would've expected the null
check first here.
Not blocking if everyone else feels that way, can deal with it in a follow up.
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.
A few test plan items are marked "address after merge". I think it would be fine to add a similar item to the test plan #36024 to see if we can improve this.
[Fact] | ||
public void Override_NullCheckedDifference() | ||
{ | ||
var source = | ||
@" | ||
class Base | ||
{ | ||
public virtual void M1(string x!!) { } | ||
public virtual void M2(string x) { } | ||
} | ||
|
||
class Derived : Base | ||
{ | ||
public override void M1(string x) { } | ||
public override void M2(string x!!) { } | ||
}"; | ||
var verifier = CompileAndVerify(source); | ||
verifier.VerifyDiagnostics(); |
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.
Not sure if it does make sense to also run this test with NRT enabled and still ensure no nullable-related warnings are produced?
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.
Sounds good. Done.
src/Compilers/CSharp/Test/Semantic/Semantics/NullCheckedParameterTests.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Semantic/Semantics/NullCheckedParameterTests.cs
Show resolved
Hide resolved
@@ -7977,7 +7986,7 @@ private void VisitThisOrBaseReference(BoundExpression node) | |||
var parameter = node.ParameterSymbol; | |||
int slot = GetOrCreateSlot(parameter); | |||
var parameterType = GetDeclaredParameterResult(parameter); | |||
var typeWithState = GetParameterState(parameterType, parameter.FlowAnalysisAnnotations); | |||
var typeWithState = GetParameterState(parameterType, parameter.FlowAnalysisAnnotations, parameter.IsNullChecked); |
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.
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.
Oop, I might not have addressed this. Looking.
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.
I think there's not an obvious scenario where we can observe a behavior difference so I'm not going to add specific tests for it at this time.
src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenNullCheckedParameterTests.cs
Show resolved
Hide resolved
…rations * upstream/main: (87 commits) Add support for nullable analysis in interpolated string handler constructors (dotnet#57780) Record list-patterns and newlines in interpolations as done (dotnet#58250) Swithc to acquiring the component model on a BG thread. Fix failure to propagate cancellation token [main] Update dependencies from dotnet/arcade (dotnet#58327) Change PROTOTYPE to issue reference (dotnet#58336) Resolve PROTOTYPE comments in param null checking (dotnet#58324) Address various minor param-nullchecking issues (dotnet#58321) Nullable enable GetTypeByMetadataName (dotnet#58317) Support CodeClass2.Parts returning parts in source generated files Allow the FileCodeModel.Parent to be null Ensure the CodeModel tests are using VisualStudioWorkspaceImpl Fix the bad words in TestDeepAlternation Fix regression in Equals/GetHashCode of LambdaSymbol. (dotnet#58247) Support "Enable nullable reference types" from disable keyword Support "Enable nullable reference types" from restore keyword Support "Enable nullable reference types" on the entire directive Add comment Remove descriptor Update src/Workspaces/Remote/ServiceHub/Services/SemanticClassification/RemoteSemanticClassificationService.cs ...
string? s!!
a warning just asint? x!!
is a warning. notes!!
. Test plan for "Parameter null-checking" #36024 (comment)