-
Notifications
You must be signed in to change notification settings - Fork 7.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
Enable nullable: System.Management.Automation.Language.TypeName #14232
base: master
Are you sure you want to change the base?
Conversation
@@ -8418,7 +8420,8 @@ public override int GetHashCode() | |||
/// </remarks> | |||
internal bool IsType(Type type) | |||
{ | |||
string fullTypeName = type.FullName; | |||
string? fullTypeName = type.FullName; | |||
Debug.Assert(fullTypeName is not 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.
Maybe we should check for null?
if (fullTypeName is null)
return 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.
The Debug.Assert
is necessary here to tell the compiler fullTypeName
is not null.
In my opinion there should an actual null check here, but in a separate PR,
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 don't think it can ever be null. Fullname is the qualified name of the type, including the namespace. I don't see how that could ever be null.
The fully qualified name of the type, including its namespace but not its assembly; or null if the current instance represents a generic type parameter, an array type, pointer type, or byref type based on a type parameter, or a generic type that is not a generic type definition but contains unresolved type parameters.
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.
Looking at the summary of the type, it says
A simple type that is not an array or does not have generic arguments.
So basically, we are meeting the requirement that it has a typename.
I think you can bang it, maybe with a comment.
i.e.
string fullTypeName = type.FullName!;
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.
string fullTypeName = type.FullName!;
What about the possible NullReferenceException in the next line?
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.
type always has a fullname in the cases this class handles.
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.
Currently, the only reference to the TypeName.IsType
method is from FunctionMemberAst.IsReturnTypeVoid
. But the method is internal
, it is accessible to any file in System.Management.Automation
, so I think we should try to avoid the NullReferenceException.
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.
Formally fullTypeName is nullable. So I am ok with adding the Debug.Assert() here. We should avoid changing a code at annotation time.
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
@powercode Can you review? |
@@ -8418,7 +8420,8 @@ public override int GetHashCode() | |||
/// </remarks> | |||
internal bool IsType(Type type) | |||
{ | |||
string fullTypeName = type.FullName; | |||
string? fullTypeName = type.FullName; | |||
Debug.Assert(fullTypeName is not 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.
I don't think it can ever be null. Fullname is the qualified name of the type, including the namespace. I don't see how that could ever be null.
The fully qualified name of the type, including its namespace but not its assembly; or null if the current instance represents a generic type parameter, an array type, pointer type, or byref type based on a type parameter, or a generic type that is not a generic type definition but contains unresolved type parameters.
@@ -8418,7 +8420,8 @@ public override int GetHashCode() | |||
/// </remarks> | |||
internal bool IsType(Type type) | |||
{ | |||
string fullTypeName = type.FullName; | |||
string? fullTypeName = type.FullName; | |||
Debug.Assert(fullTypeName is not 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.
Looking at the summary of the type, it says
A simple type that is not an array or does not have generic arguments.
So basically, we are meeting the requirement that it has a typename.
I think you can bang it, maybe with a comment.
i.e.
string fullTypeName = type.FullName!;
@@ -8981,7 +8984,7 @@ public ReflectionTypeName(Type type) | |||
/// <summary> | |||
/// The name of the assembly. | |||
/// </summary> | |||
public string AssemblyName { get { return _type.Assembly.FullName; } } | |||
public string? AssemblyName { get { return _type.Assembly.FullName; } } |
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 wonder if this will ever be null. I know that it's annotated as such on Assembly
, but I haven't been able to produce an instance of it.
@daxian-dbw, do you know?
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.
AssemblyName
is public property in public class System.Management.Automation.Language.ReflectionTypeName
, I don't think can should assume it can never return 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.
Since we use .Net API without wrapping we should follow .Net.
I suggest to keep this as is and open new tracking issue in PowerShell repo and new issue in .Net Runtime repo.
Also I guess we could suddenly get null if single file packaging is used.
Follow-up to #14088, #14181.