-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
The ConstructorBuilder and MethodBuilder generated parameter should not have default value by default #84550
Conversation
…ot has default value by default
Tagging subscribers to this area: @dotnet/area-system-reflection-emit Issue DetailsFixes #20909
|
src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs
Outdated
Show resolved
Hide resolved
@@ -202,6 +202,11 @@ private static DateTime GetRawDateTimeConstant(CustomAttributeData attr) | |||
|
|||
private object? GetDefaultValue(bool raw) | |||
{ | |||
if (IsRetval) | |||
{ | |||
return DBNull.Value; |
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.
Could not think of any case where return parameter could have a default value, double checking with the area experts CC @AaronRobinsonMSFT @jkotas @steveharter
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.
Tagging mono folks @lambdageek @marek-safar @vargaz
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.
Why is the extra if needed?
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.
Because GetDefaultValue returns null instead of DBNull.Value/Type.Missing, which makes HasDefaultValue return true for return parameters. Do we consider a return parameter in mono to have default values for a valuable reason or it is just an error ?
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 think better fix would be to update add_parameter_object_to_array
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 would fix the probem. The add_parameter_object_to_array processes only input parameters. In fact, The ReturnParameter is constructed here :
runtime/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs
Lines 135 to 138 in bc76652
internal static ParameterInfo GetReturnParameterInfo(RuntimeMethodInfo method) | |
{ | |
return RuntimeParameterInfo.New(GetReturnType(method.mhandle), method, get_retval_marshal(method.mhandle)); | |
} |
Mono does not provide DefaultValueImpl to RuntimeParameterInfo as you can see, we can add a new method in mono like get_retval_marshal that return a hardcoded DbNull.Value or do it directly in the dedicated constructor:
runtime/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs
Lines 113 to 122 in bc76652
/* to build a ParameterInfo for the return type of a method */ | |
internal RuntimeParameterInfo(Type type, MemberInfo member, MarshalAsAttribute marshalAs) | |
{ | |
this.ClassImpl = type; | |
this.MemberImpl = member; | |
this.NameImpl = null; | |
this.PositionImpl = -1; // since parameter positions are zero-based, return type pos is -1 | |
this.AttrsImpl = ParameterAttributes.Retval; | |
this.marshalAs = marshalAs; | |
} |
Let me know which one do you prefer
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.
Setting the default DbNull.Value
directly in the dedicated constructor sounds reasonable to me, ping @marek-safar for opinion
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.
LGTM, thanks @pedrobsaila
The failure unrelated and known |
Breaking change: dotnet/docs#36725 |
Fixes #20909