-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Nullable for Type class #23489
Nullable for Type class #23489
Conversation
c01bfd0 to
652234c
Compare
d7a3ba4 to
15ac27f
Compare
stephentoub
left a comment
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.
Thanks for the initial work on this. I think there are a fair number of mistakes in the APIs, though, as derived types weren't factored in. Please add to this PR the other derivations of Type that are in corelib, and then the whole thing can be re-reviewed. Otherwise the annotation of Type isn't accurate.
|
@stephentoub should it cover immediate descendants or all derived type? I guess preferably all descendants but isn't it will become too big PR in that case? |
Ideally "all". Even if it ends up being bigger, it'll help us to be more efficient in the long run, because we won't need to keep revisiting the types. It'll also be easier to review when all related types are done together. And will help to validate the correctness of the changes being reviewed. |
158c834 to
f93f7be
Compare
|
|
||
| private byte[] _IL = null!; | ||
| private ExceptionHandlingClause[] _exceptionHandlingClauses = null!; | ||
| private LocalVariableInfo[] _localVariables = null!; |
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.
The instance of this class only created using native call
coreclr/src/vm/runtimehandles.cpp
Line 2420 in 4a26541
| FCIMPL2(RuntimeMethodBody *, RuntimeMethodHandle::GetMethodBody, ReflectMethodObject *pMethodUNSAFE, ReflectClassBaseObject *pDeclaringTypeUNSAFE) |
src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs
Outdated
Show resolved
Hide resolved
| // "isDesignTime" will be "false" and "key" will point to a non-null | ||
| // license key. | ||
| public object AllocateAndValidateLicense(Type type, string? key, bool isDesignTime) | ||
| public object? AllocateAndValidateLicense(Type type, string? key, bool isDesignTime) |
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.
? [](start = 21, length = 1)
Can this be null? I'm curious because of the method name; it makes it sound like only a valid license would be returned, and I'm assuming (maybe incorrectly) that null would be an invalid license.
It doesn't matter much for this method itself, as it's internal; I just wonder whether this nullable-ness is flowing out and impacting the annotations we're adding to callers that are exposed publicly.
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.
Can this be null? I'm curious because of the method name; it makes it sound like only a valid license would be returned, and I'm assuming (maybe incorrectly) that null would be an invalid license.
marked nullable as MethodBase.Invoke(...) method called on return has nullable return. You mean if validation failed it would throw instead of returning null? From try catch most likely that is true
It doesn't matter much for this method itself, as it's internal; I just wonder whether this nullable-ness is flowing out and impacting the annotations we're adding to callers that are exposed publicly.
Checked publicly exposed method of IClassFactory and IClassFactory2 interface
void CreateInstance(
[MarshalAs(UnmanagedType.Interface)] object? pUnkOuter,
ref Guid riid,
[MarshalAs(UnmanagedType.Interface)] out object? ppvObject);
Seems paramete out object? ppvObject should be non nullable
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.
marked nullable as MethodBase.Invoke(...) method called on return has nullable return
That's because any method with any return value might be returned. You'd need to examine the particular method being invoked.
You mean if validation failed it would throw instead of returning null?
Yes, that's my question. Maybe @AaronRobinsonMSFT knows.
Seems paramete out object? ppvObject should be non nullable
The docs state:
If the object does not support the interface specified in riid, the implementation must set *ppvObject to NULL.
so I believe nullable here is correct. But that doesn't mean that it might be null for every use of this method, just that some uses could result in null.
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.
You mean if validation failed it would throw instead of returning null?
Yes, that's my question. Maybe @AaronRobinsonMSFT knows.
None of these COM functions can return null during allocation. In this scenario an Exception will be marshalled as an error HRESULT since the function method is marked as returning void. This can be observed in the exception below that throws CLASS_E_NOTLICENSED which will result in an error HRESULT to the caller - which means by COM semantics that all out parameters are in an undefined state.
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.
thank you, updated only this method to return non null
Refers to: src/System.Private.CoreLib/src/System/RtType.cs:367 in 6f10090. [](commit_id = 6f10090, deletion_comment = False) |
|
|
||
| #region Private Members | ||
| private string ConstructName(ref string name, TypeNameFormatFlags formatFlags) | ||
| private string ConstructName(ref string? name, TypeNameFormatFlags formatFlags) |
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.
ref string? name [](start = 41, length = 16)
Please add // TODO-NULLABLE: [https://github.com/dotnet/roslyn/issues/26761](https://github.com/dotnet/roslyn/issues/26761`) here
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.
added
src/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs
Outdated
Show resolved
Hide resolved
src/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs
Outdated
Show resolved
Hide resolved
src/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.cs
Outdated
Show resolved
Hide resolved
|
I did another spot-check pass through and left some comments. Let's get the remaining comments addressed, as well as the build passing, and then get this merged. Thanks! |
System.Type, System.Reflection nullability
System.Type, System.Reflection nullability
System.Type, System.Reflection nullability Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
System.Type, System.Reflection nullability Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
System.Type, System.Reflection nullability Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
System.Type, System.Reflection nullability Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
System.Type, System.Reflection nullability Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
System.Type, System.Reflection nullability Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
System.Type, System.Reflection nullability Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
System.Type, System.Reflection nullability Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
System.Type, System.Reflection nullability Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
System.Type, System.Reflection nullability Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
System.Type, System.Reflection nullability Commit migrated from dotnet/coreclr@56f38ea
No description provided.