-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Support generic type parameter when created with TypeBuilder #112372
base: main
Are you sure you want to change the base?
Conversation
src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureGenericParameterType.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureHasElementType.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureConstructedGenericType.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/TypeDelegator.cs
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/SignatureTypes.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureConstructedGenericType.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/TypeDelegator.cs
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/SignatureTypes.cs
Outdated
Show resolved
Hide resolved
private static void MyGenericValueTypeMethod<T>() where T : struct { } | ||
private static void MyGenericRefTypeMethod<T>() where T : class { } | ||
|
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.
private static void MyGenericValueTypeMethod<T>() where T : struct { } | |
private static void MyGenericRefTypeMethod<T>() where T : class { } |
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/SignatureTypes.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/SignatureTypes.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/SignatureTypes.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/SignatureTypes.cs
Outdated
Show resolved
Hide resolved
@@ -312,6 +355,8 @@ public static void MakeSignatureConstructedGenericType(Type genericTypeDefinitio | |||
Assert.False(et.IsGenericTypeParameter); | |||
Assert.True(et.IsGenericMethodParameter); | |||
Assert.Equal(5, et.GenericParameterPosition); | |||
Assert.Throws<NotSupportedException>(() => et.IsValueType); |
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.
Move up before Type et = t.GenericTypeArguments[0];
line and change to Assert.False.
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.
In this case, I wanted to make sure the new code that was added for IsValueType\IsEnum throws when the generic parameter is a signature type.
If I compare t
with t.IsValueType
that is just testing normal reflection and will return true
for Span<sigtype>
and false
for the List<sigtype>
.
{ | ||
// These have normal generic argument types, not SignatureTypes. Using a SignatureType from MakeGenericMethodParameter() | ||
// as the generic type argument throws NotSupportedException which is verified in MakeSignatureConstructedGenericType(). | ||
yield return new object[] { Type.MakeGenericSignatureType(typeof(List<>), typeof(int)).GetGenericArguments()[0], true }; |
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.
Type.MakeGenericSignatureType(typeof(List<>), typeof(int)).GetGenericArguments()[0]
is going to be typeof(int)
, so this test does not seem to be actually testing IsValueType property on signature types.
Should this rather be something like:
yield return new object[] { Type.MakeGenericSignatureType(typeof(List<>), typeof(int)), false };
yield return new object[] { Type.MakeGenericSignatureType(typeof(KeyValuePair<,>), typeof(string), typeof(object)), true };
?
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.
Correct this is not verifying signature types but is verifying that when a non-signature type is used as a generic parameter then IsValueType works as expected. The test with GetGenericArguments()
is done in MakeSignatureConstructedGenericType() as mentioned in the comment.
I'm not sure if your feedback here came before or after I pushed a new commit that changed this and added the comment.
{ | ||
// These have normal generic argument types, not SignatureTypes. Using a SignatureType from MakeGenericMethodParameter() | ||
// as the generic type argument throws NotSupportedException which is verified in MakeSignatureConstructedGenericType(). | ||
yield return new object[] { Type.MakeGenericSignatureType(typeof(List<>), typeof(MyEnum)).GetGenericArguments()[0], true }; |
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.
Dtto
Fixes #112155
There may be other related edge cases related to "signature types"; this PR only fixes the case mentioned.