-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add/update AssemblyBuilder/PersistedAssemblyBuilder tests covering boundary / edge case scenarios #105782
Conversation
@@ -33,7 +33,7 @@ internal PropertyBuilderImpl(string name, PropertyAttributes attributes, Calling | |||
_name = name; | |||
_attributes = attributes; | |||
_callingConvention = callingConvention; | |||
_propertyType = returnType; | |||
_propertyType = returnType ?? containingType.GetModuleBuilder().GetTypeFromCoreAssembly(CoreTypeId.Void); |
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.
Existing AssemblyBuilder
adds void type for null return type when populating the signature, now this scenario causing NRE in the SignatureHelper, I could fix it in the signature only, but to avoid NRE's for other case setting the return type to void 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.
The constructor parameter, Type returnType
isn't marked as nullable. If a null
value is sneaking through, we should fix that or mark the parameter as 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.
Yes, allowing null might was not intentional, but making it throw for null now probably will be breaking change. We might also want to move the null handling from SignatureHelper
to RuntimePropertyBuilder
runtime/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/SignatureHelper.cs
Lines 144 to 150 in 9fe8c95
public static SignatureHelper GetPropertySigHelper(Module? mod, CallingConventions callingConvention, | |
Type? returnType, Type[]? requiredReturnTypeCustomModifiers, Type[]? optionalReturnTypeCustomModifiers, | |
Type[]? parameterTypes, Type[][]? requiredParameterTypeCustomModifiers, Type[][]? optionalParameterTypeCustomModifiers) | |
{ | |
SignatureHelper sigHelp; | |
returnType ??= typeof(void); |
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.
Sure, that makes sense. I don't think we should throw either, but I do like to have the nullable indicators correct so we can check these things.
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.
Done
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.
Existing AssemblyBuilder adds void type for null return type when populating the signature,
I assume this behavior exists in previous versions as well?
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.
Yes, RuntimePropertyBuilder
constructor was allowing null, but not handling null which could cause NRE further if SetConstant
called for the property, the null has been resolved only for GetPropertySigHelper
. I see same behavior in .NET framework.
Now with this PR the null
return type will be handled to void type in the RuntimePropertyBuilder
constructor, same as in GetPropertySigHelper
.
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineField.cs
Show resolved
Hide resolved
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.
Some misc questions, but otherwise LGTM
Buyaa out, merged. |
It was considered useful to add tests for the following cases:
Fixes #103086