Skip to content

Commit

Permalink
Test to create ByRefLike instance through a generic parameter (#101004)
Browse files Browse the repository at this point in the history
* Test to create ByRefLike instance through a generic parameter
  • Loading branch information
AaronRobinsonMSFT committed Apr 13, 2024
1 parent 715e697 commit b2db851
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/tests/Loader/classloader/generics/ByRefLike/InvalidCSharp.il
Expand Up @@ -73,6 +73,26 @@

.field public !T Field

.method public hidebysig
instance !T CreateDefaultInstance() cil managed
{
.locals init (
[0] !T
)
ldloca.s 0
initobj !T
ldloc.0
ret
}

.method public hidebysig
instance class [System.Runtime]System.Type GetGenericType() cil managed
{
ldtoken !T
call class [System.Runtime]System.Type [System.Runtime]System.Type::GetTypeFromHandle(valuetype [System.Runtime]System.RuntimeTypeHandle)
ret
}

.method public hidebysig
instance object BoxAsObject(!T) cil managed
{
Expand Down Expand Up @@ -564,6 +584,24 @@
ret
}

.method public hidebysig static
string CreateDefaultInstance() cil managed
{
.locals init (
[0] valuetype InvalidCSharp.GenericByRefLike_Over`1<valuetype ByRefLikeType>
)

ldloca.s 0
initobj valuetype InvalidCSharp.GenericByRefLike_Over`1<valuetype ByRefLikeType>
ldloca.s 0
call instance !0 valuetype InvalidCSharp.GenericByRefLike_Over`1<valuetype ByRefLikeType>::CreateDefaultInstance()
pop
ldloca.s 0
call instance class [System.Runtime]System.Type valuetype InvalidCSharp.GenericByRefLike_Over`1<valuetype ByRefLikeType>::GetGenericType()
callvirt instance string [System.Runtime]System.Object::ToString()
ret
}

.method public hidebysig static
object BoxAsObject() cil managed
{
Expand Down
Expand Up @@ -21,6 +21,7 @@ public static void Validate_TypeLoad()
Console.WriteLine($" -- Instantiate: {Exec.GenericValueType()}");
Console.WriteLine($" -- Instantiate: {Exec.GenericByRefLike()}");
Console.WriteLine($" -- Instantiate: {Exec.GenericByRefLike_ConstraintsAreIndependent_Int32_Int32()}");
Console.WriteLine($" -- Create: {Exec.CreateDefaultInstance()}");

Assert.Throws<TypeLoadException>(() => { Exec.GenericClass_Invalid(); });
Assert.Throws<TypeLoadException>(() => { Exec.GenericInterface_Invalid(); });
Expand Down

0 comments on commit b2db851

Please sign in to comment.