-
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
Fix: Incorrect order of checks for TypeBuilder GetConstructor
and GetField
method
#53645
Fix: Incorrect order of checks for TypeBuilder GetConstructor
and GetField
method
#53645
Conversation
cc: @eerhardt |
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderGetConstructor.cs
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs
Outdated
Show resolved
Hide resolved
GetConstructor and GetField had the same incorrect checks order comparing to GetMethod as in the CoreCLR. To keep the consistent solution, Mono has also been adjusted.
@BartoszKlonowski - looks like it is still failing on mono. |
@eerhardt Unfortunately, I've tried to understand the order of checks for Mono - |
@lambdageek - any thoughts on the mono checks here? Can you help @BartoszKlonowski out? |
@BartoszKlonowski I think you need something like this change in Mono's GetField and GetConstructor - ie instead always throwing if the type is a generic type definition you should instead check whether the generic type definition that |
@lambdageek Thank you! Can you verify if I understood your advice correctly? |
|
||
if (type == null) | ||
throw new ArgumentException("Type is not generic", nameof(type)); | ||
|
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 this needs the same code that GetMethod
has:
if (type is TypeBuilder && type.ContainsGenericParameters)
type = type.MakeGenericType(type.GetGenericArguments());
(and same for GetField)
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've tried, but it won't build.
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.
Looks like you also need
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2055:UnrecognizedReflectionPattern",
Justification = "Type.MakeGenericType is used to create a typical instantiation")]
|
||
return res; | ||
} | ||
|
||
private static bool IsValidGetMethodType(Type type) |
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.
Can you put this method back where it was originally declared? That will make reviewing the change much easier. Also when people look at source history, will be able to see what change was made here easily. #Closed
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderGetConstructor.cs
Outdated
Show resolved
Hide resolved
@eerhardt Since you're the most active reviewer on this, I assigned this PR to you for follow-up/decision before the RC1 snap. |
@BartoszKlonowski - I left 2 pieces of feedback above. Let me know if you will address these, or if you want me to resolve them. That way we can move this PR forward. |
Looks like the tests are still failing:
|
Tests are still failing:
Are you able to run them locally? That would give you a faster turn around to get the CI green. |
@eerhardt I'm afraid I won't be able to finish this, sorry. I really appreciate your help and support, but analysing this and fixing the issue with tests would require much more time than I currently have... |
@eerhardt if you want to take over this PR, please do so ASAP otherwise I recommend closing. Thanks |
I'll get to this PR once I am finished with my 6.0 deliverables. |
Ensure checks are consistent across GetConstructor, GetField, and GetMethod for both coreclr and mono.
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!
This pull request fixes #45988
It changes the order of checks for
GetConstructor
andGetField
method according to the workflow ofGetMethod
.Full explanation can be found in the linked issue.
Because of reordered checks of those method, unit tests had to be adjusted.
For both
GetField
andGetConstructor
they now check whether for not generic type the element will be created without throwing.