Skip to content
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

Merged
merged 13 commits into from
May 31, 2023

Conversation

pedrobsaila
Copy link
Contributor

Fixes #20909

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Apr 9, 2023
@ghost
Copy link

ghost commented Apr 9, 2023

Tagging subscribers to this area: @dotnet/area-system-reflection-emit
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #20909

Author: pedrobsaila
Assignees: -
Labels:

area-System.Reflection.Emit

Milestone: -

@@ -202,6 +202,11 @@ private static DateTime GetRawDateTimeConstant(CustomAttributeData attr)

private object? GetDefaultValue(bool raw)
{
if (IsRetval)
{
return DBNull.Value;
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor Author

@pedrobsaila pedrobsaila Apr 24, 2023

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 ?

Copy link
Contributor

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

Copy link
Contributor Author

@pedrobsaila pedrobsaila May 4, 2023

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 :

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:

/* 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

Copy link
Contributor

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

@pedrobsaila pedrobsaila changed the title The ConstructorBuilder and MethodBuilder generated parameter should not has default value by default The ConstructorBuilder and MethodBuilder generated parameter should not have default value by default May 4, 2023
Copy link
Contributor

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @pedrobsaila

@steveharter steveharter self-requested a review May 31, 2023 17:11
@buyaa-n
Copy link
Contributor

buyaa-n commented May 31, 2023

The failure unrelated and known

@buyaa-n buyaa-n merged commit 3c0c801 into dotnet:main May 31, 2023
@pedrobsaila pedrobsaila deleted the 20909 branch May 31, 2023 18:02
@ghost ghost locked as resolved and limited conversation to collaborators Jun 30, 2023
@steveharter steveharter added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Jul 17, 2023
@steveharter
Copy link
Member

Breaking change: dotnet/docs#36725

@ericstj ericstj added this to the 8.0.0 milestone Oct 16, 2023
@steveharter steveharter removed the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Oct 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Reflection.Emit community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The ConstructorBuilder and MethodBuilder generated parameter should not has default value by default.
5 participants