Skip to content

Commit

Permalink
Add test for ByRefLike testing when constraints (#99415)
Browse files Browse the repository at this point in the history
are across multiple generic parameters.
  • Loading branch information
AaronRobinsonMSFT authored Mar 7, 2024
1 parent 49a8bb7 commit 709097d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/tests/Loader/classloader/generics/ByRefLike/InvalidCSharp.il
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,18 @@
.field public static !T StaticField
}

.class public sequential ansi sealed beforefieldinit InvalidCSharp.GenericClass_IndependentConstraints`2<byreflike T, (!T) U>
extends [System.Runtime]System.Object
{
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
ldarg.0
call instance void [System.Runtime]System.Object::.ctor()
ret
}
}

.class public sequential ansi sealed beforefieldinit ByRefLikeType
extends [System.Runtime]System.ValueType
{
Expand All @@ -355,6 +367,19 @@
)
}

.class interface public auto ansi abstract InvalidCSharp.EmptyInterface
{
}

.class public sequential ansi sealed beforefieldinit InvalidCSharp.ByRefLikeTypeWithInterface
extends [System.Runtime]System.ValueType
implements InvalidCSharp.EmptyInterface
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = (
01 00 00 00
)
}

.class public sequential ansi sealed beforefieldinit RegularValueType
extends [System.Runtime]System.ValueType
{
Expand Down Expand Up @@ -516,6 +541,27 @@
callvirt instance string [System.Runtime]System.Object::ToString()
ret
}
.method public hidebysig static
class [System.Runtime]System.Type GenericByRefLike_ConstraintsAreIndependent_Int32_Int32() cil managed
{
newobj instance void class InvalidCSharp.GenericClass_IndependentConstraints`2<int32, int32>::.ctor()
callvirt instance class [System.Runtime]System.Type [System.Runtime]System.Object::GetType()
ret
}
.method public hidebysig static
class [System.Runtime]System.Type GenericByRefLike_ConstraintsAreIndependent_Interface_ByRefLike_Invalid() cil managed
{
newobj instance void class InvalidCSharp.GenericClass_IndependentConstraints`2<class InvalidCSharp.ByRefLikeTypeWithInterface, valuetype InvalidCSharp.ByRefLikeTypeWithInterface>::.ctor()
callvirt instance class [System.Runtime]System.Type [System.Runtime]System.Object::GetType()
ret
}
.method public hidebysig static
class [System.Runtime]System.Type GenericByRefLike_ConstraintsAreIndependent_ByRefLike_ByRefLike_Invalid() cil managed
{
newobj instance void class InvalidCSharp.GenericClass_IndependentConstraints`2<valuetype InvalidCSharp.ByRefLikeTypeWithInterface, valuetype InvalidCSharp.ByRefLikeTypeWithInterface>::.ctor()
callvirt instance class [System.Runtime]System.Type [System.Runtime]System.Object::GetType()
ret
}

.method public hidebysig static
object BoxAsObject() cil managed
Expand Down
3 changes: 3 additions & 0 deletions src/tests/Loader/classloader/generics/ByRefLike/Validate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ public static void Validate_TypeLoad()
Console.WriteLine($" -- Instantiate: {Exec.GenericInterface()}");
Console.WriteLine($" -- Instantiate: {Exec.GenericValueType()}");
Console.WriteLine($" -- Instantiate: {Exec.GenericByRefLike()}");
Console.WriteLine($" -- Instantiate: {Exec.GenericByRefLike_ConstraintsAreIndependent_Int32_Int32()}");

Assert.Throws<TypeLoadException>(() => { Exec.GenericClass_Invalid(); });
Assert.Throws<TypeLoadException>(() => { Exec.GenericInterface_Invalid(); });
Assert.Throws<TypeLoadException>(() => { Exec.GenericValueType_Invalid(); });
Assert.Throws<TypeLoadException>(() => { Exec.GenericByRefLike_Invalid(); });
Assert.Throws<TypeLoadException>(() => { Exec.GenericByRefLike_ConstraintsAreIndependent_Interface_ByRefLike_Invalid(); });
Assert.Throws<TypeLoadException>(() => { Exec.GenericByRefLike_ConstraintsAreIndependent_ByRefLike_ByRefLike_Invalid(); });
}

[Fact]
Expand Down

0 comments on commit 709097d

Please sign in to comment.