Enable nullable: System.Management.Automation.Language.TypeName#14232
Enable nullable: System.Management.Automation.Language.TypeName#14232xtqqczze wants to merge 1 commit intoPowerShell:masterfrom
Conversation
| { | ||
| string fullTypeName = type.FullName; | ||
| string? fullTypeName = type.FullName; | ||
| Debug.Assert(fullTypeName is not null); |
There was a problem hiding this comment.
Maybe we should check for null?
if (fullTypeName is null)
return false;There was a problem hiding this comment.
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.
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.
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.
string fullTypeName = type.FullName!;
What about the possible NullReferenceException in the next line?
There was a problem hiding this comment.
type always has a fullname in the cases this class handles.
There was a problem hiding this comment.
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.
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? |
| { | ||
| string fullTypeName = type.FullName; | ||
| string? fullTypeName = type.FullName; | ||
| Debug.Assert(fullTypeName is not null); |
There was a problem hiding this comment.
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.
| { | ||
| string fullTypeName = type.FullName; | ||
| string? fullTypeName = type.FullName; | ||
| Debug.Assert(fullTypeName is not null); |
There was a problem hiding this comment.
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!;| /// 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.
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.
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.
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.
|
Nice to have but too old. |
|
📣 Hey @@xtqqczze, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
Follow-up to #14088, #14181.