-
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
Test plan for "Parameter null-checking" #36024
Comments
I added a bunch of test scenarios from today's LDM decision. |
Need to consider |
From discussion with BCL and runtime folks, we've landed on:
|
I think this shouldn't emit a null reference return warning: https://sharplab.io/#v2:EYLgZgpghgLgrgJwgZwLQAcoKgW1QOzgBsiBjACwlIGsBLfAcwBoYQE58AfAYkJKmBEIAAgj4BQgLAAoAAIAmAIwyZsxQAZhAUXzJEEAHIB7GAeJEAFGvUB+YcgCEDgJQyA3jOFfhsgOz2AbhkAXxU5RQBOCx09JGNTcwsAIkAeDcAQfaTnZwCgA |
@hez2010 It looks like there are few attributes that should be generated by the compiler but are not currently.: [CompilerGenerated]
internal sealed class <PrivateImplementationDetails>
{
+ [DoesNotReturn]
internal static void Throw(string paramName)
{
throw new ArgumentNullException(paramName);
}
- internal static void ThrowIfNull(object argument, string paramName)
+ internal static void ThrowIfNull([NotNull] object? argument, string paramName)
{
if (argument == null)
{
Throw(paramName);
}
}
}
This may help the flow analysis to work properly. But @RikkiGibson can confirm whether I'm correct. |
If the functions were explicitly called they would need the attributes you've indicated, @Youssef1313. However, the Thanks for catching this issue @hez2010! |
@jaredpar Should this be closed? |
This is a place to collect test ideas.
Proposal: dotnet/csharplang#2145
Specification
csharplang
linkif/throw
)Infrastructure
Parsing
string s !!= null
parsed asstring s!! = null
Generics
void M<T>(T value!) { }
is OKvoid M<T>(T value!) where T : struct { }
is an errorvoid M<T>(T value!) where T : unmanaged { }
is an errorvoid M<T>(T value!) where T : notnull { }
is OKvoid M<T>(T value!) where T : class { }
is OKvoid M<T>(T value!) where T : SomeStruct { }
is an errorvoid M<T>(T value!) where T : SomeClass { }
is OKIterators
Null checking should always happen in initial call, not lowered methods
Constructors
Null checking should be the first thing in a constructor
this
callbase
callNested functions
delegate (object o!!) { }
x!! => x
,(x, y!!) => y
_!! => { }
Warnings and errors
null
valuestring? x!
(null-check doesn't make sense on those)int x!
parametersout string x!
(null-check doesn't make sense onout
parameter)interface
members,abstract
,extern
, declaration portion of apartial
method)Misc.
S? s!!
forstruct
typeS
Misc (from discussion in LDM)
params
parameter (allowed, checks the array, not the elements)void M<T>(T t!) where T : notnull { ... }
(ok)__arglist!!
From test plan review
async
iterator methodsref
orin
parameters? resolution: Allow. Allow 'ref' and 'in' parameters to be null-checked #58938T
does not box whenT
is a nullable value type (include aThrowIfNull<T>(T value, string parameterName)
helper method?) (delaying till after feature merge)Nullable<T>
parameters.delegate
declarationoverride
andinterface
implementation with/without!!
is allowedSymbolDisplay
is not affectedSyntaxNormalizer
, quick info, typing, completionProductivity
The text was updated successfully, but these errors were encountered: