From b7e35b9c3d87ba84b859f9f9f795857dfbbda653 Mon Sep 17 00:00:00 2001 From: Fadi Hanna Date: Mon, 11 Apr 2016 17:27:01 -0700 Subject: Bulk port of TypeSystem test cases --- .../Negative/Method_ClassConstraint_Neg.il | 2 + .../Negative/Method_ClassConstraint_Neg.ilproj | 23 +- .../Negative/Method_Constraints_Negative.csproj | 28 +- .../Method_DefaultCtorAndClassConstraint_Neg.il | 2 + ...Method_DefaultCtorAndClassConstraint_Neg.ilproj | 23 +- .../Method_DefaultCtorAndStructConstraint_Neg.il | 2 + ...ethod_DefaultCtorAndStructConstraint_Neg.ilproj | 23 +- .../Negative/Method_DefaultCtorConstraint_Neg.il | 2 + .../Method_DefaultCtorConstraint_Neg.ilproj | 23 +- .../Negative/Method_StructConstraint_Neg.il | 2 + .../Negative/Method_StructConstraint_Neg.ilproj | 23 +- .../ConstraintsOnMethod/Negative/app.config | 4 +- .../ConstraintsOnMethod/Negative/project.json | 26 +- .../ConstraintsOnMethod/Negative/types.il | 2 + .../ConstraintsOnMethod/Negative/types.ilproj | 25 +- .../Positive/Method_ClassConstraint_Pos.il | 171 +++++++ .../Positive/Method_ClassConstraint_Pos.ilproj | 38 ++ .../Positive/Method_Constraints_Positive.cs | 158 +++++++ .../Positive/Method_Constraints_Positive.csproj | 48 ++ .../Method_DefaultCtorAndClassConstraint_Pos.il | 82 ++++ ...Method_DefaultCtorAndClassConstraint_Pos.ilproj | 38 ++ .../Method_DefaultCtorAndStructConstraint_Pos.il | 110 +++++ ...ethod_DefaultCtorAndStructConstraint_Pos.ilproj | 38 ++ .../Positive/Method_DefaultCtorConstraint_Pos.il | 134 ++++++ .../Method_DefaultCtorConstraint_Pos.ilproj | 38 ++ .../Positive/Method_StructConstraint_Pos.il | 112 +++++ .../Positive/Method_StructConstraint_Pos.ilproj | 38 ++ .../ConstraintsOnMethod/Positive/app.config | 27 ++ .../ConstraintsOnMethod/Positive/project.json | 35 ++ .../ConstraintsOnMethod/Positive/types.il | 117 +++++ .../ConstraintsOnMethod/Positive/types.ilproj | 38 ++ .../Negative/Instantiation_ClassConstraint_Neg.il | 87 ++++ .../Instantiation_ClassConstraint_Neg.ilproj | 38 ++ .../Negative/Instantiation_Constraints_Neg.cs | 187 ++++++++ .../Negative/Instantiation_Constraints_Neg.csproj | 48 ++ ...tantiation_DefaultCtorAndClassConstraint_Neg.il | 209 +++++++++ ...iation_DefaultCtorAndClassConstraint_Neg.ilproj | 38 ++ ...iation_DefaultCtorAndClassTypeConstraint_Neg.il | 223 +++++++++ ...on_DefaultCtorAndClassTypeConstraint_Neg.ilproj | 42 ++ ...antiation_DefaultCtorAndStructConstraint_Neg.il | 178 ++++++++ ...ation_DefaultCtorAndStructConstraint_Neg.ilproj | 38 ++ .../Instantiation_DefaultCtorConstraint_Neg.il | 146 ++++++ .../Instantiation_DefaultCtorConstraint_Neg.ilproj | 38 ++ .../Negative/Instantiation_StructConstraint_Neg.il | 176 +++++++ .../Instantiation_StructConstraint_Neg.ilproj | 38 ++ .../Interface_DefaultCtorAndClassConstraint_Neg.il | 189 ++++++++ ...erface_DefaultCtorAndClassConstraint_Neg.ilproj | 38 ++ ...erface_DefaultCtorAndClassTypeConstraint_Neg.il | 233 ++++++++++ ...ce_DefaultCtorAndClassTypeConstraint_Neg.ilproj | 42 ++ ...Interface_DefaultCtorAndStructConstraint_Neg.il | 190 ++++++++ ...rface_DefaultCtorAndStructConstraint_Neg.ilproj | 38 ++ .../Interface_DefaultCtorConstraint_Neg.il | 165 +++++++ .../Interface_DefaultCtorConstraint_Neg.ilproj | 38 ++ .../ConstraintsOnType/Negative/RunTestNeg.il | 318 +++++++++++++ .../ConstraintsOnType/Negative/RunTestNeg.ilproj | 42 ++ .../ConstraintsOnType/Negative/RunTestNeg2.il | 504 +++++++++++++++++++++ .../ConstraintsOnType/Negative/RunTestNeg2.ilproj | 38 ++ .../ConstraintsOnType/Negative/RunTestNeg3.il | 484 ++++++++++++++++++++ .../ConstraintsOnType/Negative/RunTestNeg3.ilproj | 38 ++ .../Secondary_Ctor_Constraints_Type_Negative.cs | 208 +++++++++ ...Secondary_Ctor_Constraints_Type_Negative.csproj | 48 ++ .../Negative/StaticField_ClassConstraint_Neg.il | 93 ++++ .../StaticField_ClassConstraint_Neg.ilproj | 38 ++ .../Negative/StaticField_Constraints_Neg.cs | 187 ++++++++ .../Negative/StaticField_Constraints_Neg.csproj | 48 ++ ...taticField_DefaultCtorAndClassConstraint_Neg.il | 218 +++++++++ ...cField_DefaultCtorAndClassConstraint_Neg.ilproj | 38 ++ ...aticField_DefaultCtorAndStructConstraint_Neg.il | 181 ++++++++ ...Field_DefaultCtorAndStructConstraint_Neg.ilproj | 38 ++ .../StaticField_DefaultCtorConstraint_Neg.il | 131 ++++++ .../StaticField_DefaultCtorConstraint_Neg.ilproj | 38 ++ .../Negative/StaticField_StructConstraint_Neg.il | 179 ++++++++ .../StaticField_StructConstraint_Neg.ilproj | 38 ++ .../Negative/StaticMethod_ClassConstraint_Neg.il | 87 ++++ .../StaticMethod_ClassConstraint_Neg.ilproj | 38 ++ .../Negative/StaticMethod_Constraints_Neg.cs | 181 ++++++++ .../Negative/StaticMethod_Constraints_Neg.csproj | 48 ++ ...aticMethod_DefaultCtorAndClassConstraint_Neg.il | 187 ++++++++ ...Method_DefaultCtorAndClassConstraint_Neg.ilproj | 38 ++ ...ticMethod_DefaultCtorAndStructConstraint_Neg.il | 162 +++++++ ...ethod_DefaultCtorAndStructConstraint_Neg.ilproj | 38 ++ .../StaticMethod_DefaultCtorConstraint_Neg.il | 123 +++++ .../StaticMethod_DefaultCtorConstraint_Neg.ilproj | 38 ++ .../Negative/StaticMethod_StructConstraint_Neg.il | 162 +++++++ .../StaticMethod_StructConstraint_Neg.ilproj | 38 ++ .../Negative/TypeParam2_Constraints_Neg.cs | 121 +++++ .../Negative/TypeParam2_Constraints_Neg.csproj | 43 ++ .../Negative/TypeParam3_Constraints_Neg.cs | 123 +++++ .../Negative/TypeParam3_Constraints_Neg.csproj | 43 ++ .../ConstraintsOnType/Negative/app.config | 27 ++ .../ConstraintsOnType/Negative/project.json | 35 ++ .../ConstraintsOnType/Negative/types.il | 117 +++++ .../ConstraintsOnType/Negative/types.ilproj | 38 ++ .../ConstraintsOnType/Negative/types_implementI.il | 131 ++++++ .../Negative/types_implementI.ilproj | 38 ++ .../Negative/types_implementI_extendC.il | 150 ++++++ .../Negative/types_implementI_extendC.ilproj | 38 ++ .../Positive/Instantiation_ClassConstraint_Pos.il | 166 +++++++ .../Instantiation_ClassConstraint_Pos.ilproj | 38 ++ .../Positive/Instantiation_Constraints_Pos.cs | 151 ++++++ .../Positive/Instantiation_Constraints_Pos.csproj | 48 ++ ...tantiation_DefaultCtorAndClassConstraint_Pos.il | 80 ++++ ...iation_DefaultCtorAndClassConstraint_Pos.ilproj | 38 ++ ...iation_DefaultCtorAndClassTypeConstraint_Pos.il | 77 ++++ ...on_DefaultCtorAndClassTypeConstraint_Pos.ilproj | 38 ++ ...antiation_DefaultCtorAndStructConstraint_Pos.il | 104 +++++ ...ation_DefaultCtorAndStructConstraint_Pos.ilproj | 38 ++ .../Instantiation_DefaultCtorConstraint_Pos.il | 144 ++++++ .../Instantiation_DefaultCtorConstraint_Pos.ilproj | 38 ++ .../Positive/Instantiation_StructConstraint_Pos.il | 104 +++++ .../Instantiation_StructConstraint_Pos.ilproj | 38 ++ .../Interface_DefaultCtorAndClassConstraint_Pos.il | 68 +++ ...erface_DefaultCtorAndClassConstraint_Pos.ilproj | 38 ++ ...erface_DefaultCtorAndClassTypeConstraint_Pos.il | 68 +++ ...ce_DefaultCtorAndClassTypeConstraint_Pos.ilproj | 38 ++ ...Interface_DefaultCtorAndStructConstraint_Pos.il | 66 +++ ...rface_DefaultCtorAndStructConstraint_Pos.ilproj | 38 ++ .../Interface_DefaultCtorConstraint_Pos.il | 86 ++++ .../Interface_DefaultCtorConstraint_Pos.ilproj | 38 ++ .../ConstraintsOnType/Positive/RunTestPos.il | 52 +++ .../ConstraintsOnType/Positive/RunTestPos.ilproj | 42 ++ .../ConstraintsOnType/Positive/RunTestPos2.il | 57 +++ .../ConstraintsOnType/Positive/RunTestPos2.ilproj | 42 ++ .../ConstraintsOnType/Positive/RunTestPos3.il | 57 +++ .../ConstraintsOnType/Positive/RunTestPos3.ilproj | 42 ++ .../Positive/StaticField_ClassConstraint_Pos.il | 173 +++++++ .../StaticField_ClassConstraint_Pos.ilproj | 38 ++ .../Positive/StaticField_Constraints_Pos.cs | 157 +++++++ .../Positive/StaticField_Constraints_Pos.csproj | 48 ++ ...taticField_DefaultCtorAndClassConstraint_Pos.il | 83 ++++ ...cField_DefaultCtorAndClassConstraint_Pos.ilproj | 38 ++ ...aticField_DefaultCtorAndStructConstraint_Pos.il | 112 +++++ ...Field_DefaultCtorAndStructConstraint_Pos.ilproj | 38 ++ .../StaticField_DefaultCtorConstraint_Pos.il | 133 ++++++ .../StaticField_DefaultCtorConstraint_Pos.ilproj | 38 ++ .../Positive/StaticField_StructConstraint_Pos.il | 108 +++++ .../StaticField_StructConstraint_Pos.ilproj | 38 ++ .../Positive/StaticMethod_ClassConstraint_Pos.il | 154 +++++++ .../StaticMethod_ClassConstraint_Pos.ilproj | 38 ++ .../Positive/StaticMethod_Constraints_Pos.cs | 152 +++++++ .../Positive/StaticMethod_Constraints_Pos.csproj | 48 ++ ...aticMethod_DefaultCtorAndClassConstraint_Pos.il | 79 ++++ ...Method_DefaultCtorAndClassConstraint_Pos.ilproj | 38 ++ ...ticMethod_DefaultCtorAndStructConstraint_Pos.il | 102 +++++ ...ethod_DefaultCtorAndStructConstraint_Pos.ilproj | 38 ++ .../StaticMethod_DefaultCtorConstraint_Pos.il | 124 +++++ .../StaticMethod_DefaultCtorConstraint_Pos.ilproj | 38 ++ .../Positive/StaticMethod_StructConstraint_Pos.il | 101 +++++ .../StaticMethod_StructConstraint_Pos.ilproj | 38 ++ .../ConstraintsOnType/Positive/app.config | 27 ++ .../ConstraintsOnType/Positive/project.json | 35 ++ .../ConstraintsOnType/Positive/types.il | 117 +++++ .../ConstraintsOnType/Positive/types.ilproj | 38 ++ .../ConstraintsOnType/Positive/types_implementI.il | 131 ++++++ .../Positive/types_implementI.ilproj | 38 ++ .../Positive/types_implementI_extendC.il | 151 ++++++ .../Positive/types_implementI_extendC.ilproj | 38 ++ .../Constraints/General/ManyGenConstraints.cs | 155 +++++++ .../Constraints/General/ManyGenConstraints.csproj | 39 ++ .../generics/Constraints/General/app.config | 27 ++ .../generics/Constraints/General/project.json | 35 ++ .../Constraints/Recursion/RecursiveConstraints.cs | 198 ++++++++ .../Recursion/RecursiveConstraints.csproj | 39 ++ .../generics/Constraints/Recursion/app.config | 27 ++ .../generics/Constraints/Recursion/project.json | 35 ++ .../Constraints/Regressions/532403/VSW532403.cs | 132 ++++++ .../Regressions/532403/VSW532403.csproj | 39 ++ .../Constraints/Regressions/532403/app.config | 27 ++ .../Constraints/Regressions/532403/project.json | 35 ++ .../Constraints/Regressions/ddb62403/app.config | 27 ++ .../Constraints/Regressions/ddb62403/bug62403.cs | 30 ++ .../Regressions/ddb62403/bug62403.csproj | 39 ++ .../Constraints/Regressions/ddb62403/project.json | 35 ++ .../Regressions/dev10_512868/app.config | 27 ++ .../Regressions/dev10_512868/dev10_512868.cs | 188 ++++++++ .../Regressions/dev10_512868/dev10_512868.csproj | 39 ++ .../Regressions/dev10_512868/project.json | 35 ++ .../Constraints/Regressions/vsw609874/app.config | 27 ++ .../Constraints/Regressions/vsw609874/project.json | 35 ++ .../Constraints/Regressions/vsw609874/vsw609874.cs | 37 ++ .../Regressions/vsw609874/vsw609874.csproj | 39 ++ 181 files changed, 14407 insertions(+), 104 deletions(-) create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_ClassConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_ClassConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_Constraints_Positive.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_Constraints_Positive.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndClassConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndClassConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndStructConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndStructConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_StructConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_StructConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/app.config create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/project.json create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/types.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/types.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_ClassConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_ClassConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_Constraints_Neg.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_Constraints_Neg.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassTypeConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassTypeConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndStructConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndStructConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_StructConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_StructConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassTypeConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassTypeConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndStructConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndStructConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg2.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg2.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg3.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg3.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Secondary_Ctor_Constraints_Type_Negative.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Secondary_Ctor_Constraints_Type_Negative.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_ClassConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_ClassConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_Constraints_Neg.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_Constraints_Neg.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndClassConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndClassConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndStructConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndStructConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_StructConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_StructConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_ClassConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_ClassConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_Constraints_Neg.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_Constraints_Neg.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndClassConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndClassConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndStructConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndStructConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_StructConstraint_Neg.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_StructConstraint_Neg.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam2_Constraints_Neg.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam2_Constraints_Neg.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam3_Constraints_Neg.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam3_Constraints_Neg.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/app.config create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/project.json create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI_extendC.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI_extendC.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_ClassConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_ClassConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_Constraints_Pos.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_Constraints_Pos.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassTypeConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassTypeConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndStructConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndStructConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_StructConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_StructConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassTypeConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassTypeConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndStructConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndStructConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos2.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos2.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos3.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos3.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_ClassConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_ClassConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_Constraints_Pos.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_Constraints_Pos.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndClassConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndClassConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndStructConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndStructConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_StructConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_StructConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_ClassConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_ClassConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_Constraints_Pos.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_Constraints_Pos.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndClassConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndClassConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndStructConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndStructConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_StructConstraint_Pos.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_StructConstraint_Pos.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/app.config create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/project.json create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI_extendC.il create mode 100644 tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI_extendC.ilproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/General/ManyGenConstraints.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/General/ManyGenConstraints.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/General/app.config create mode 100644 tests/src/Loader/classloader/generics/Constraints/General/project.json create mode 100644 tests/src/Loader/classloader/generics/Constraints/Recursion/RecursiveConstraints.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/Recursion/RecursiveConstraints.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/Recursion/app.config create mode 100644 tests/src/Loader/classloader/generics/Constraints/Recursion/project.json create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/532403/VSW532403.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/532403/VSW532403.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/532403/app.config create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/532403/project.json create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/app.config create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/bug62403.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/bug62403.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/project.json create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/app.config create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/dev10_512868.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/dev10_512868.csproj create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/project.json create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/app.config create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/project.json create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/vsw609874.cs create mode 100644 tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/vsw609874.csproj (limited to 'tests/src/Loader/classloader/generics/Constraints') diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.il index 454cdc53f8..1ad189851f 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.il +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.il @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +.assembly extern System.Console { } + .assembly extern mscorlib{} .assembly extern types{} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.ilproj index 7187cb451a..1798e52f10 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.ilproj +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_ClassConstraint_Neg.ilproj @@ -1,4 +1,4 @@ - + @@ -7,37 +7,32 @@ AnyCPU 2.0 {95DFC527-4DC1-495E-97D7-E94EE1F7140D} - Library 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - ..\..\ 7a9bfb7d true - false + true + Library BuildOnly - 1 - - - - - + 0 + False + - + + - - - \ No newline at end of file + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.csproj index b8677916bb..dbfebd583d 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.csproj +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_Constraints_Negative.csproj @@ -1,4 +1,4 @@ - + @@ -7,37 +7,31 @@ AnyCPU 2.0 {95DFC527-4DC1-495E-97D7-E94EE1F7140D} - Exe 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - ..\..\ 7a9bfb7d true false + Exe BuildAndRun - 1 - - - - - + 0 + False + - + - - - + @@ -46,7 +40,9 @@ + + + + - - - \ No newline at end of file + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.il index fd926bb4fe..ac585b387d 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.il +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.il @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +.assembly extern System.Console { } + .assembly extern mscorlib{} .assembly extern types{} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.ilproj index ec74a8cafe..7d3463cbcf 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.ilproj +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndClassConstraint_Neg.ilproj @@ -1,4 +1,4 @@ - + @@ -7,37 +7,32 @@ AnyCPU 2.0 {95DFC527-4DC1-495E-97D7-E94EE1F7140D} - Library 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - ..\..\ 7a9bfb7d true - false + true + Library BuildOnly - 1 - - - - - + 0 + False + - + + - - - \ No newline at end of file + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.il index 5214b72882..17b2cfde50 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.il +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.il @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +.assembly extern System.Console { } + .assembly extern mscorlib{} .assembly extern types{} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.ilproj index d5f7e5dc6d..1e49b3a613 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.ilproj +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorAndStructConstraint_Neg.ilproj @@ -1,4 +1,4 @@ - + @@ -7,37 +7,32 @@ AnyCPU 2.0 {95DFC527-4DC1-495E-97D7-E94EE1F7140D} - Library 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - ..\..\ 7a9bfb7d true - false + true + Library BuildOnly - 1 - - - - - + 0 + False + - + + - - - \ No newline at end of file + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.il index 9bf744bc72..eaed96b0db 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.il +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.il @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +.assembly extern System.Console { } + .assembly extern mscorlib{} .assembly extern types{} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.ilproj index d0d36a934d..1ba82f71f9 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.ilproj +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_DefaultCtorConstraint_Neg.ilproj @@ -1,4 +1,4 @@ - + @@ -7,37 +7,32 @@ AnyCPU 2.0 {95DFC527-4DC1-495E-97D7-E94EE1F7140D} - Library 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - ..\..\ 7a9bfb7d true - false + true + Library BuildOnly - 1 - - - - - + 0 + False + - + + - - - \ No newline at end of file + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.il index 570576c59a..315cb05a21 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.il +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.il @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +.assembly extern System.Console { } + .assembly extern mscorlib{} .assembly extern types{} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.ilproj index 3611ac569b..9b799cd78c 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.ilproj +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/Method_StructConstraint_Neg.ilproj @@ -1,4 +1,4 @@ - + @@ -7,37 +7,32 @@ AnyCPU 2.0 {95DFC527-4DC1-495E-97D7-E94EE1F7140D} - Library 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - ..\..\ 7a9bfb7d true - false + true + Library BuildOnly - 1 - - - - - + 0 + False + - + + - - - \ No newline at end of file + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/app.config b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/app.config index 62803f5972..e5622f77ad 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/app.config +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/app.config @@ -1,4 +1,4 @@ - + @@ -24,4 +24,4 @@ - \ No newline at end of file + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/project.json b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/project.json index cda793f996..a2e84dc340 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/project.json +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/project.json @@ -1,9 +1,33 @@ { "dependencies": { "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", "System.Runtime": "4.1.0-rc2-23816", - "System.Runtime.Extensions": "4.0.10" + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" }, "frameworks": { "dnxcore50": {} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.il index a43bb72b20..53c0b9e255 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.il +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.il @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +.assembly extern System.Console { } + .assembly extern mscorlib{} .assembly Types {} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.ilproj index 9fc7db8e42..e90ddd06ea 100644 --- a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.ilproj +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Negative/types.ilproj @@ -1,4 +1,4 @@ - + @@ -7,37 +7,32 @@ AnyCPU 2.0 {95DFC527-4DC1-495E-97D7-E94EE1F7140D} - Library 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - ..\..\ 7a9bfb7d true - false + true + Library BuildOnly - 1 - - - - - + 0 + False + - - + + + - - - \ No newline at end of file + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_ClassConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_ClassConstraint_Pos.il new file mode 100644 index 0000000000..ec498b24ef --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_ClassConstraint_Pos.il @@ -0,0 +1,171 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Method_ClassConstraint_Pos {} + + + +.class public auto ansi beforefieldinit B + extends [mscorlib]System.Object +{ + + // Generic method with class() constraint + .method public hidebysig instance void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit M_ClassConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class B::.ctor() + call instance void class B::method1() + ret + } + + // POSITIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class B::.ctor() + call instance void class B::method1() + ret + } + + + // POSITIVE TEST + // generic argument is a delegate + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class B::.ctor() + call instance void class B::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class B::.ctor() + call instance void class B::method1() + ret + } + + + + // POSITIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + newobj instance void class B::.ctor() + call instance void class B::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an interface + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + newobj instance void class B::.ctor() + call instance void class B::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class B::.ctor() + call instance void class B::method1() + + ret + } + + + +} + +.class public auto ansi beforefieldinit M_ClassConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class B::.ctor() + call instance void class B::method1>() + + ret + } + + // POSITIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class B::.ctor() + call instance void class B::method1>() + + ret + } + + + // POSITIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class B::.ctor() + call instance void class B::method1>() + + ret + } + + +} + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_ClassConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_ClassConstraint_Pos.ilproj new file mode 100644 index 0000000000..0dea3bb999 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_ClassConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Method_ClassConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_Constraints_Positive.cs b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_Constraints_Positive.cs new file mode 100644 index 0000000000..9533f0a104 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_Constraints_Positive.cs @@ -0,0 +1,158 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// POSITIVE TESTS +/* Test various combinations of constraints on methods +CONSTRAINTS: + +default ctor +reference type +valuetype +default ctor, reference tyoe +default ctor, valuetype + +Test each constraint with +- Class with default nullary ctor (Generic/Non generic) +- Class with no default nullary ctor (Generic/Non generic) +- Class from mscorlib with default nullary ctor +- Abstract Class from mscorlib with no default nullary ctor + +- Struct from mscorlib (Generic/Non generic) +- Struct (Generic/Non generic) +- Enum (Generic/Non generic) + +- Interface (Generic/Non generic) + +- Array + +- Delegate + +- Nullable +*/ + +using System; + + +public class Test +{ + static bool pass; + static int testNumber = 1; + + delegate void Case(); + + + static void Check(Case mytest, string testName, string violatingType, string type) + { + + Console.Write("Test"+testNumber + ": " + testName); + ++testNumber; + + + try + { + mytest(); + + + Console.WriteLine(" : PASS"); + return; + } + catch (TypeLoadException e) + { + Console.WriteLine("\nFAIL: Caught unexpected TypeLoadException: " + e); + pass = false; + return; + } + + catch (Exception e) + { + Console.WriteLine("\nFAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + + + public static int Main() + { + pass = true; + + Console.WriteLine("POSITIVE TESTS"); + + Console.WriteLine("\nType: A where T : new()\n"); + + Check(new Case(M_DefaultCtorConstraint.Test1), "Generic argument is a class with default ctor", "N/A", "N/A"); + Check(new Case(M_DefaultCtorConstraint.Test3), "Generic argument is a struct (valuetypes have public nullary ctors by default)", "N/A", "N/A"); + Check(new Case(M_DefaultCtorConstraint.Test5), "Generic argument is an mscorlib class with default ctor", "N/A", "N/A"); + + // enum is a valueypte and all valuetypes have public nullary ctors. + Check(new Case(M_DefaultCtorConstraint.Test8), "Generic argument is an enum", "N/A", "N/A"); + + + Check(new Case(M_DefaultCtorConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor", "N/A", "N/A"); + Check(new Case(M_DefaultCtorConstraintGenTypes.Test3), "Generic argument is a generic struct", "N/A", "N/A"); + Check(new Case(M_DefaultCtorConstraintGenTypes.Test6), "Generic argument is Nullable", "N/A", "N/A"); + + + + Console.WriteLine("\nType: A where T : class()\n"); + + + Check(new Case(M_ClassConstraint.Test1), "Generic argument is a class with default ctor", "N/A", "N/A"); + Check(new Case(M_ClassConstraint.Test2), "Generic argument is a class with no default ctor", "N/A", "N/A"); + Check(new Case(M_ClassConstraint.Test4), "Generic argument is a delegate", "N/A", "N/A"); + Check(new Case(M_ClassConstraint.Test5), "Generic argument is an mscorlib class with default ctor", "N/A", "N/A"); + Check(new Case(M_ClassConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "N/A", "N/A"); + Check(new Case(M_ClassConstraint.Test7), "Generic argument is an interface", "N/A", "N/A"); + + + Check(new Case(M_ClassConstraint.Test9), "Generic argument is an array of classes with default ctor", "N/A", "N/A"); + + Check(new Case(M_ClassConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor", "N/A", "N/A"); + Check(new Case(M_ClassConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "N/A", "N/A"); + Check(new Case(M_ClassConstraintGenTypes.Test5), "Generic argument is a generic interface", "N/A", "N/A"); + + Console.WriteLine("\nType: A where T : struct()\n"); + + + Check(new Case(M_StructConstraint.Test3), "Generic argument is a struct", "N/A", "N/A"); + Check(new Case(M_StructConstraint.Test8), "Generic argument is an enum", "N/A", "N/A"); + Check(new Case(M_StructConstraint.Test9), "Generic argument is an mscorlib struct", "N/A", "N/A"); + + Check(new Case(M_StructConstraintGenTypes.Test3), "Generic argument is a generic struct", "N/A", "N/A"); + Check(new Case(M_StructConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct", "N/A", "N/A"); + + + + Console.WriteLine("\nType: A where T : class(), new() \n"); + + Check(new Case(M_DefaultCtorAndClassConstraint.Test1), "Generic argument is a class with default ctor", "N/A", "N/A"); + Check(new Case(M_DefaultCtorAndClassConstraint.Test5), "Generic argument is a is an mscorlib class with default ctor", "N/A", "N/A"); + Check(new Case(M_DefaultCtorAndClassConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor", "N/A", "N/A"); + + + + Console.WriteLine("\nType: A where T : struct(), new()\n"); + + + Check(new Case(M_DefaultCtorAndStructConstraint.Test3), "Generic argument is a struct", "N/A", "N/A"); + Check(new Case(M_DefaultCtorAndStructConstraint.Test9), "Generic argument is an mscorlib struct", "N/A", "N/A"); + Check(new Case(M_DefaultCtorAndStructConstraintGenTypes.Test3), "Generic argument is a generic struct", "N/A", "N/A"); + Check(new Case(M_DefaultCtorAndStructConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct", "N/A", "N/A"); + Check(new Case(M_DefaultCtorAndStructConstraint.Test8), "Generic argument is an enum", "N/A", "N/A"); + + if (pass) + { + Console.WriteLine("PASS"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + } +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_Constraints_Positive.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_Constraints_Positive.csproj new file mode 100644 index 0000000000..11baa29070 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_Constraints_Positive.csproj @@ -0,0 +1,48 @@ + + + + + Method_Constraints_Positive + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndClassConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndClassConstraint_Pos.il new file mode 100644 index 0000000000..bdfe960750 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndClassConstraint_Pos.il @@ -0,0 +1,82 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Method_DefaultCtorAndClassConstraint_Pos {} + + + +.class public auto ansi beforefieldinit D + extends [mscorlib]System.Object +{ + + // Generic method with class() and new() constraints + .method public hidebysig instance void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + + + +} + +.class public auto ansi beforefieldinit M_DefaultCtorAndClassConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class D::.ctor() + call instance void class D::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class D::.ctor() + call instance void class D::method1() + + ret + } + +} + +.class public auto ansi beforefieldinit M_DefaultCtorAndClassConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class D::.ctor() + call instance void class D::method1>() + + ret + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndClassConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndClassConstraint_Pos.ilproj new file mode 100644 index 0000000000..b4ff4c337d --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndClassConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Method_DefaultCtorAndClassConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndStructConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndStructConstraint_Pos.il new file mode 100644 index 0000000000..c9b223f097 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndStructConstraint_Pos.il @@ -0,0 +1,110 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Method_DefaultCtorAndStructConstraint_Pos {} + + + +.class public auto ansi beforefieldinit E + extends [mscorlib]System.Object +{ + + // Generic method with struct() and new() constraints + .method public hidebysig instance void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit M_DefaultCtorAndStructConstraint + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class E::.ctor() + call instance void class E::method1() + + ret + } + + // POSITIVE TEST + // generic argument is an enum + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class E::.ctor() + call instance void class E::method1() + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib struct + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class E::.ctor() + call instance void class E::method1() + ret + } + +} + +.class public auto ansi beforefieldinit M_DefaultCtorAndStructConstraintGenTypes + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class E::.ctor() + call instance void class E::method1>() + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib generic struct + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class E::.ctor() + call instance void class E::method1>() + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndStructConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndStructConstraint_Pos.ilproj new file mode 100644 index 0000000000..958c9f1630 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorAndStructConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Method_DefaultCtorAndStructConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorConstraint_Pos.il new file mode 100644 index 0000000000..71e7662830 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorConstraint_Pos.il @@ -0,0 +1,134 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Method_DefaultCtorConstraint_Pos {} + + +.class public auto ansi beforefieldinit A + extends [mscorlib]System.Object +{ + + // Generic method with new() constraint + .method public hidebysig instance void + method1<.ctor T>() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit M_DefaultCtorConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + newobj instance void class A::.ctor() + call instance void class A::method1() + ret + } + + + // POSITIVE TEST + // generic argument is a struct (valuetypes have public nullary ctors by default) + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + newobj instance void class A::.ctor() + call instance void class A::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class A::.ctor() + call instance void class A::method1() + ret + } + + + + // POSITIVE TEST + // generic argument is an enum with no default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class A::.ctor() + call instance void class A::method1() + ret + } + + +} + +.class public auto ansi beforefieldinit M_DefaultCtorConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class A::.ctor() + call instance void class A::method1>() + ret + } + + + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class A::.ctor() + call instance void class A::method1>() + + ret + } + + + + // POSITIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class A::.ctor() + call instance void class A::method1>() + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorConstraint_Pos.ilproj new file mode 100644 index 0000000000..12545dfb80 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_DefaultCtorConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Method_DefaultCtorConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_StructConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_StructConstraint_Pos.il new file mode 100644 index 0000000000..284d48e0f4 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_StructConstraint_Pos.il @@ -0,0 +1,112 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Method_StructConstraint_Pos {} + + + +.class public auto ansi beforefieldinit C + extends [mscorlib]System.Object +{ + + // Generic method with class() constraint + .method public hidebysig instance void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit M_StructConstraint + extends [mscorlib]System.Object +{ + + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class C::.ctor() + call instance void class C::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an enum + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class C::.ctor() + call instance void class C::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib struct + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class C::.ctor() + call instance void class C::method1() + + ret + } + +} + +.class public auto ansi beforefieldinit M_StructConstraintGenTypes + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class C::.ctor() + call instance void class C::method1>() + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib generic struct + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class C::.ctor() + call instance void class C::method1>() + + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_StructConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_StructConstraint_Pos.ilproj new file mode 100644 index 0000000000..f16948d7e8 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/Method_StructConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Method_StructConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/app.config b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/app.config new file mode 100644 index 0000000000..e5622f77ad --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/project.json b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/project.json new file mode 100644 index 0000000000..a2e84dc340 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/types.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/types.il new file mode 100644 index 0000000000..53c0b9e255 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/types.il @@ -0,0 +1,117 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} + +.assembly Types {} + +// class with public nullary ctor +.class public auto ansi beforefieldinit ClassWithCtor + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +// generic class with public nullary ctor +.class public auto ansi beforefieldinit GenClassWithCtor + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +// class without public nullary ctor +.class public auto ansi beforefieldinit ClassNoCtor + extends [mscorlib]System.Object +{ +} + +// generic class without public nullary ctor +.class public auto ansi beforefieldinit GenClassNoCtor + extends [mscorlib]System.Object +{ +} + + +// struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit NonGenStruct + extends [mscorlib]System.ValueType +{ + .pack 0 + .size 1 +} + + + +// generic struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit GenStruct + extends [mscorlib]System.ValueType +{ + .pack 0 + .size 1 +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit NonGenInterface +{ +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit GenInterface +{ +} + + +.class public auto ansi sealed Enum1 + extends [mscorlib]System.Enum +{ + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype Enum1 One = int32(0x00000000) +} + + +// doesn't have public parameterless constructor +.class public auto ansi sealed Delegate1 + extends [mscorlib]System.MulticastDelegate +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor(object 'object', + native int 'method') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void Invoke() runtime managed + { + } + + .method public hidebysig newslot virtual + instance class [mscorlib]System.IAsyncResult + BeginInvoke(class [mscorlib]System.AsyncCallback callback, + object 'object') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void EndInvoke(class [mscorlib]System.IAsyncResult result) runtime managed + { + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/types.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/types.ilproj new file mode 100644 index 0000000000..e90ddd06ea --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnMethod/Positive/types.ilproj @@ -0,0 +1,38 @@ + + + + + types + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_ClassConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_ClassConstraint_Neg.il new file mode 100644 index 0000000000..dfe74b8207 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_ClassConstraint_Neg.il @@ -0,0 +1,87 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Instantiation_ClassConstraint_Neg {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit B`1 + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit ClassConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class B`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an enum with no default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class B`1::.ctor() + pop + + ret + } +} + +.class public auto ansi beforefieldinit ClassConstraintGenTypes + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class B`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class B`1>::.ctor() + pop + + ret + } +} + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_ClassConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_ClassConstraint_Neg.ilproj new file mode 100644 index 0000000000..cfb4c80e0c --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_ClassConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + Instantiation_ClassConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_Constraints_Neg.cs b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_Constraints_Neg.cs new file mode 100644 index 0000000000..0166e701e2 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_Constraints_Neg.cs @@ -0,0 +1,187 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/* Test various combinations of constraints with illegal parameter types by instantiating the types + +CONSTRAINTS: + +default ctor +reference type +valuetype +default ctor, reference type +default ctor, valuetype + +Test each constraint with (whichever applies to negative tests) +- Class with default nullary ctor (Generic/Non generic) +- Class with no default nullary ctor (Generic/Non generic) +- Class from mscorlib with default nullary ctor +- Abstract Class from mscorlib with no default nullary ctor + +- Struct from mscorlib (Generic/Non generic) +- Struct (Generic/Non generic) +- Enum (Generic/Non generic) + +- Interface (Generic/Non generic) + +- Array + +- Delegate + +- Nullable + + + +*/ + +using System; + + +public class Test +{ + static bool pass; + static int testNumber = 1; + + delegate void Case(); + + + static void Check(Case mytest, string testName, string violatingType, string type) + { + + Console.Write("Test"+testNumber + ": " + testName); + ++testNumber; + + + try + { + mytest(); + + Console.WriteLine("\nFAIL: Did not catch expected TypeLoadException"); + pass = false; + } + catch (TypeLoadException e) + { + // Unhandled Exception: System.TypeLoadException: %0, '%1', on '%2' + // violates the constraint of type parameter '%3'. + + Test.CheckTypeLoadExceptionMessage(8310, e, violatingType, type); + } + + catch (Exception e) + { + Console.WriteLine("\nFAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + + public static void CheckTypeLoadExceptionMessage(uint ResourceID, TypeLoadException e, string violatingType, string type ) + { + if ( + !e.ToString().Contains("0") || + !e.ToString().Contains(violatingType) || + !e.ToString().Contains(type) || + !e.ToString().Contains("T")) + { + Console.WriteLine("Exception message is incorrect"); + pass = false; + } + else + { + Console.WriteLine("Caught expected exception"); + } + } + + + public static int Main() + { + pass = true; + + Console.WriteLine("\nType: A where T : new()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(DefaultCtorConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "A`1[T]"); + Check(new Case(DefaultCtorConstraint.Test4), "Generic argument is a delegate", "Delegate1", "A`1[T]"); + Check(new Case(DefaultCtorConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "A`1[T]"); + Check(new Case(DefaultCtorConstraint.Test7), "Generic argument is an interface with no default ctor", "NonGenInterface", "A`1[T]"); + Check(new Case(DefaultCtorConstraint.Test9), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "A`1[T]"); + Check(new Case(DefaultCtorConstraintGenTypes.Test2), " Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "A`1[T]"); + Check(new Case(DefaultCtorConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "A`1[T]"); + + + + Console.WriteLine("\nType: A where T : class()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(ClassConstraint.Test3), "Generic argument is a struct", "NonGenStruct", "B`1[T]"); + Check(new Case(ClassConstraint.Test8), "Generic argument is an enum", "Enum1", "B`1[T]"); + Check(new Case(ClassConstraintGenTypes.Test3), "Generic argument is a generic struct with default ctor", "GenStruct[System.Int32]", "B`1[T]"); + Check(new Case(ClassConstraintGenTypes.Test6), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "B`1[T]"); + + + Console.WriteLine("\nType: A where T : struct()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(StructConstraint.Test1), "Generic argument is a class with default ctor", "ClassWithCtor", "C`1[T]"); + Check(new Case(StructConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "C`1[T]"); + Check(new Case(StructConstraint.Test4), "Generic argument is a delegate", "Delegate1", "C`1[T]"); + Check(new Case(StructConstraint.Test5), "Generic argument is an mscorlib class with default ctor", "System.Object", "C`1[T]"); + Check(new Case(StructConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "C`1[T]"); + Check(new Case(StructConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "C`1[T]"); + Check(new Case(StructConstraint.Test10), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "C`1[T]"); + Check(new Case(StructConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor", "GenClassWithCtor[System.Int32]", "C`1[T]"); + Check(new Case(StructConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "C`1[T]"); + Check(new Case(StructConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "C`1[T]"); + Check(new Case(StructConstraintGenTypes.Test7), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "C`1[T]"); + + + + Console.WriteLine("\nType: A where T : class(), new() \n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(DefaultCtorAndClassConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraint.Test3), "Generic argument is a struct", "NonGenStruct", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraint.Test4), "Generic argument is a delegate", "Delegate1", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraint.Test9), "Generic argument is an mscorlib struct", "System.DateTime", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraint.Test8), "Generic argument is an enum", "Enum1", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraint.Test10), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraintGenTypes.Test3), "Generic argument is a generic struct", "GenStruct[System.Int32]", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct", "System.Collections.Generic.KeyValuePair`2[NonGenStruct,System.Int32]", "D`1[T]"); + Check(new Case(DefaultCtorAndClassConstraintGenTypes.Test7), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "D`1[T]"); + + + Console.WriteLine("\nType: A where T : struct(), new()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(DefaultCtorAndStructConstraint.Test1), "Generic argument is a class with default ctor", "ClassWithCtor", "E`1[T]"); + Check(new Case(DefaultCtorAndStructConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "E`1[T]"); + Check(new Case(DefaultCtorAndStructConstraint.Test4), "Generic argument is a delegate", "Delegate1", "E`1[T]"); + Check(new Case(DefaultCtorAndStructConstraint.Test5), "Generic argument is an mscorlib class with default ctor", "System.Object", "E`1[T]"); + Check(new Case(DefaultCtorAndStructConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "E`1[T]"); + Check(new Case(DefaultCtorAndStructConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "E`1[T]"); + Check(new Case(DefaultCtorAndStructConstraint.Test10), "Generic argument is an array of classes with default ctor", "NonGenStruct[]", "E`1[T]"); + Check(new Case(DefaultCtorAndStructConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor", "GenClassWithCtor[System.Int32]", "E`1[T]"); + Check(new Case(DefaultCtorAndStructConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "E`1[T]"); + Check(new Case(DefaultCtorAndStructConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "E`1[T]"); + Check(new Case(DefaultCtorAndStructConstraintGenTypes.Test7), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "E`1[T]"); + + + if (pass) + { + Console.WriteLine("PASS"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + } +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_Constraints_Neg.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_Constraints_Neg.csproj new file mode 100644 index 0000000000..19f8ea1469 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_Constraints_Neg.csproj @@ -0,0 +1,48 @@ + + + + + Instantiation_Constraints_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassConstraint_Neg.il new file mode 100644 index 0000000000..37f590114a --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassConstraint_Neg.il @@ -0,0 +1,209 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Instantiation_DefaultCtorAndClassConstraint_Neg {} + + +// Generic class with class() and new() constraints +.class public auto ansi beforefieldinit D`1 + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + + + +} + +.class public auto ansi beforefieldinit DefaultCtorAndClassConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a delegate (doesn't have public parameterless constructor) + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + newobj instance void class D`1::.ctor() + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an enum + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib struct + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } +} + +.class public auto ansi beforefieldinit DefaultCtorAndClassConstraintGenTypes + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class D`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a generic struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class D`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an generic interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class D`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib generic struct + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class D`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class D`1>::.ctor() + pop + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassConstraint_Neg.ilproj new file mode 100644 index 0000000000..c835970db4 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + Instantiation_DefaultCtorAndClassConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassTypeConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassTypeConstraint_Neg.il new file mode 100644 index 0000000000..8cbb4d092c --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassTypeConstraint_Neg.il @@ -0,0 +1,223 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types_implementI_extendC {} + +.assembly Instantiation_DefaultCtorAndClassTypeConstraint_Neg {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit F`1<.ctor ([types_implementI_extendC]C) T> + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + + + +.class public auto ansi beforefieldinit Instantiation_DefaultCtorAndClassTypeConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with default ctor that doesn't extend C + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a delegate (doesn't have public parameterless constructor) + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an enum (has default ctor since it's a valuetype) + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test11() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a generic class with default ctor that implements I but doesn't extend C + .method public hidebysig static void Test12() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a struct (valuetypes have public nullary ctors by default) + .method public hidebysig static void Test13() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test14() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + + + + + + + + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassTypeConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassTypeConstraint_Neg.ilproj new file mode 100644 index 0000000000..9d9f4959b9 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndClassTypeConstraint_Neg.ilproj @@ -0,0 +1,42 @@ + + + + + Instantiation_DefaultCtorAndClassTypeConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndStructConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndStructConstraint_Neg.il new file mode 100644 index 0000000000..7edb3d609b --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndStructConstraint_Neg.il @@ -0,0 +1,178 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Instantiation_DefaultCtorAndStructConstraint_Neg {} + + +// Generic class with struct() and new() constraints +.class public auto ansi beforefieldinit E`1 + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit DefaultCtorAndStructConstraint + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a delegate + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + newobj instance void class E`1::.ctor() + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } +} + +.class public auto ansi beforefieldinit DefaultCtorAndStructConstraintGenTypes + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class E`1>::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class E`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class E`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class E`1>::.ctor() + pop + + ret + } +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndStructConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndStructConstraint_Neg.ilproj new file mode 100644 index 0000000000..e6068f0920 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorAndStructConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + Instantiation_DefaultCtorAndStructConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorConstraint_Neg.il new file mode 100644 index 0000000000..60da97a375 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorConstraint_Neg.il @@ -0,0 +1,146 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Instantiation_DefaultCtorConstraint_Neg {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit A`1<.ctor T> + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit DefaultCtorConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + + ret + } + + + // NEGATIVE TEST + // generic argument is a delegate (doesn't have public parameterless constructor) + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + // generic argument is NUllable + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + +} + +.class public auto ansi beforefieldinit DefaultCtorConstraintGenTypes + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class A`1>::.ctor() + pop + + ret + } + + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class A`1>::.ctor() + pop + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorConstraint_Neg.ilproj new file mode 100644 index 0000000000..766a567ddc --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_DefaultCtorConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + Instantiation_DefaultCtorConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_StructConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_StructConstraint_Neg.il new file mode 100644 index 0000000000..27f71b129b --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_StructConstraint_Neg.il @@ -0,0 +1,176 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Instantiation_StructConstraint_Neg {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit C`1 + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit StructConstraint + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class C`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class C`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a delegate + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class C`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class C`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + newobj instance void class C`1::.ctor() + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class C`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + newobj instance void class C`1::.ctor() + pop + + ret + } +} + +.class public auto ansi beforefieldinit StructConstraintGenTypes + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class C`1>::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class C`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class C`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class C`1>::.ctor() + pop + + ret + } +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_StructConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_StructConstraint_Neg.ilproj new file mode 100644 index 0000000000..daad12889c --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Instantiation_StructConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + Instantiation_StructConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassConstraint_Neg.il new file mode 100644 index 0000000000..6b794e184d --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassConstraint_Neg.il @@ -0,0 +1,189 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types_implementI{} + +.assembly Interface_DefaultCtorAndClassConstraint_Neg {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit D`1 + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit Interface_DefaultCtorAndClassConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a delegate (doesn't have public parameterless constructor) + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an enum (has default ctor since it's a valuetype) + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class D`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class D`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + newobj instance void class D`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a struct (valuetypes have public nullary ctors by default) + .method public hidebysig static void Test11() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test12() cil managed + { + .maxstack 1 + + newobj instance void class D`1>::.ctor() + pop + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassConstraint_Neg.ilproj new file mode 100644 index 0000000000..40eb841f32 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + Interface_DefaultCtorAndClassConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassTypeConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassTypeConstraint_Neg.il new file mode 100644 index 0000000000..73f3f7529d --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassTypeConstraint_Neg.il @@ -0,0 +1,233 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types_implementI_extendC {} + +.assembly Interface_DefaultCtorAndClassTypeConstraint_Neg {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit F`1 + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + + + +.class public auto ansi beforefieldinit Interface_DefaultCtorAndClassTypeConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with default ctor that implements I but doesn't extend C + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a delegate (doesn't have public parameterless constructor) + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an enum (has default ctor since it's a valuetype) + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test11() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a generic class with default ctor that implements I but doesn't extend C + .method public hidebysig static void Test12() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a struct (valuetypes have public nullary ctors by default) + .method public hidebysig static void Test13() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test14() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a class with default ctor that doesn't implements I but extends C + .method public hidebysig static void Test15() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + + + + + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassTypeConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassTypeConstraint_Neg.ilproj new file mode 100644 index 0000000000..402afc6280 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndClassTypeConstraint_Neg.ilproj @@ -0,0 +1,42 @@ + + + + + Interface_DefaultCtorAndClassTypeConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndStructConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndStructConstraint_Neg.il new file mode 100644 index 0000000000..ea076ff329 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndStructConstraint_Neg.il @@ -0,0 +1,190 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types_implementI{} + +.assembly Interface_DefaultCtorAndStructConstraint_Neg {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit E`1 + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit Interface_DefaultCtorAndStructConstraint + extends [mscorlib]System.Object +{ + + + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a delegate (doesn't have public parameterless constructor) + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an enum (has default ctor since it's a valuetype) + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class E`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + newobj instance void class E`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test11() cil managed + { + .maxstack 1 + + newobj instance void class E`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test12() cil managed + { + .maxstack 1 + + newobj instance void class E`1>::.ctor() + pop + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndStructConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndStructConstraint_Neg.ilproj new file mode 100644 index 0000000000..8804ce1fd6 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorAndStructConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + Interface_DefaultCtorAndStructConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorConstraint_Neg.il new file mode 100644 index 0000000000..5e3abe0975 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorConstraint_Neg.il @@ -0,0 +1,165 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types_implementI{} + +.assembly Interface_DefaultCtorConstraint_Neg {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit A`1<.ctor ([types_implementI]I) T> + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit Interface_DefaultCtorConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a delegate (doesn't have public parameterless constructor) + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an enum (has default ctor since it's a valuetype) + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + +// NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class A`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class A`1>::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + newobj instance void class A`1>::.ctor() + pop + + ret + } + + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorConstraint_Neg.ilproj new file mode 100644 index 0000000000..9e9a1e7422 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Interface_DefaultCtorConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + Interface_DefaultCtorConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg.il new file mode 100644 index 0000000000..a5c0ab1493 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg.il @@ -0,0 +1,318 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib {} +.assembly extern TypeParam_Constraints_Neg {} +.assembly RunTestNeg {} + + +.class public auto ansi beforefieldinit GClass`2<(!U) T,class U> + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit GStruct`2<(!U) T, valuetype U> + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +.class public auto ansi beforefieldinit GNew`2<(!U) T,.ctor U> + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit GClassType`2<(!U) T,([TypeParam_Constraints_Neg]A) U> + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit GInterfaceType`2<(!U) T,([TypeParam_Constraints_Neg]I) U> + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +// =============================================================================== + +.class public auto ansi beforefieldinit RunGClassTest + extends [mscorlib]System.Object +{ + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + newobj instance void class GClass`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + newobj instance void class GClass`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + newobj instance void class GClass`2::.ctor() + pop + ret + } + + + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + newobj instance void class GClass`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + newobj instance void class GClass`2::.ctor() + pop + ret + } +} + +// =============================================================================== + +.class public auto ansi beforefieldinit RunGStructTest + extends [mscorlib]System.Object +{ + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + newobj instance void class GStruct`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + newobj instance void class GStruct`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + newobj instance void class GStruct`2::.ctor() + pop + ret + } + + + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + newobj instance void class GStruct`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + newobj instance void class GStruct`2::.ctor() + pop + ret + } + +} + +// =============================================================================== + + +.class public auto ansi beforefieldinit RunGNewTest + extends [mscorlib]System.Object +{ + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + newobj instance void class GNew`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + newobj instance void class GNew`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + newobj instance void class GNew`2::.ctor() + pop + ret + } + + + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + newobj instance void class GNew`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + newobj instance void class GNew`2::.ctor() + pop + ret + } + +} + +// =============================================================================== + +.class public auto ansi beforefieldinit RunGClassTypeTest + extends [mscorlib]System.Object +{ + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + newobj instance void class GClassType`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + newobj instance void class GClassType`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + newobj instance void class GClassType`2::.ctor() + pop + ret + } + + + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + newobj instance void class GClassType`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + newobj instance void class GClassType`2::.ctor() + pop + ret + } + +} + +// =============================================================================== + +.class public auto ansi beforefieldinit RunGInterfaceTypeTest + extends [mscorlib]System.Object +{ + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + newobj instance void class GInterfaceType`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + newobj instance void class GInterfaceType`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + newobj instance void class GInterfaceType`2::.ctor() + pop + ret + } + + + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + newobj instance void class GInterfaceType`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + newobj instance void class GInterfaceType`2::.ctor() + pop + ret + } + +} + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg.ilproj new file mode 100644 index 0000000000..d347a1a2d5 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg.ilproj @@ -0,0 +1,42 @@ + + + + + RunTestNeg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg2.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg2.il new file mode 100644 index 0000000000..90f076dfba --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg2.il @@ -0,0 +1,504 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } +// See test descriptions below + +.assembly extern mscorlib {} + +.assembly RunTestNeg2 {} + + +.class public auto ansi beforefieldinit A + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public sequential ansi sealed beforefieldinit S + extends [mscorlib]System.ValueType + implements I +{ + .pack 0 + .size 1 +} + + + + +.class interface public abstract auto ansi I {} + + + +.class private auto ansi beforefieldinit GClass`1 + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit GStruct`1 + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +.class public auto ansi beforefieldinit GNew`1<.ctor T> + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +// ============================================================ + + +.class private auto ansi beforefieldinit G1`1 + extends class GClass`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +.class private auto ansi beforefieldinit G2`1<(I) P> + extends class GClass`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class private auto ansi beforefieldinit G3`1<([mscorlib]System.Object) P> + extends class GClass`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class private auto ansi beforefieldinit G4`1<([mscorlib]System.ValueType) P> + extends class GClass`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +.class private auto ansi beforefieldinit G5`1<([mscorlib]System.Enum) P> + extends class GClass`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + // ============================================================ + + +.class private auto ansi beforefieldinit G6`1 + extends class GStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class private auto ansi beforefieldinit G7`1<(A) P> + extends class GStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +.class private auto ansi beforefieldinit G8`1<(I) P> + extends class GStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class private auto ansi beforefieldinit G12`1<(System.ValueType) P> + extends class GStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class private auto ansi beforefieldinit G13`1<(valuetype [mscorlib]System.'Nullable`1') P> + extends class GStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + + // ============================================================ + +.class public auto ansi beforefieldinit G9`1<(A) P> + extends class GNew`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit G10`1 + extends class GNew`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit G11`1<(I) P> + extends class GNew`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + // ============================================================ + +.class public auto ansi beforefieldinit RunTest + extends [mscorlib]System.Object +{ + + // TEST 1 + // NEGATIVE + // T has 'class' constraint BUT + // P has 'struct' constraint + // use a class as type param + .method public hidebysig static void Test1() cil managed + { + + .maxstack 1 + newobj instance void class G1`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 2 + // NEGATIVE + // T has 'class' constraint BUT + // P has 'struct' constraint + // use a struct as type param + .method public hidebysig static void Test2() cil managed + { + + .maxstack 1 + newobj instance void class G1`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 3 + // NEGATIVE + // T has 'class' constraint BUT + // P has interface-type constraint + // This is a secondary constraint - this tells us nothing about the eventual instantiation that + // we can use here. + + .method public hidebysig static void Test3() cil managed + { + + .maxstack 1 + newobj instance void class G2`1::.ctor() + pop + ret + } + + + // ===================================================================== + + // TEST 4 + // NEGATIVE + // T has 'class' constraint BUT + // P has System.Object constraint + .method public hidebysig static void Test4() cil managed + { + + .maxstack 1 + newobj instance void class G3`1::.ctor() + pop + ret + } + + + // ===================================================================== + + // TEST 5 + // NEGATIVE + // T has 'class' constraint BUT + // P has System.ValueType constraint + .method public hidebysig static void Test5() cil managed + { + + .maxstack 1 + newobj instance void class G4`1::.ctor() + pop + ret + } + + + // ===================================================================== + + // TEST 6 + // NEGATIVE + // T has 'class' constraint BUT + // P has System.Enum constraint + .method public hidebysig static void Test6() cil managed + { + + .maxstack 1 + newobj instance void class G5`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 7 + // NEGATIVE + // T has 'struct' constraint BUT + // P has 'class' constraint + // instantiated with a class + .method public hidebysig static void Test7() cil managed + { + + .maxstack 1 + newobj instance void class G6`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 8 + // NEGATIVE + // T has 'struct' constraint BUT + // P has 'class' constraint + // instantiated with a struct + .method public hidebysig static void Test8() cil managed + { + + .maxstack 1 + newobj instance void class G6`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 9 + // NEGATIVE + // T has 'struct' constraint BUT + // P has 'class-type' constraint + .method public hidebysig static void Test9() cil managed + { + + .maxstack 1 + newobj instance void class G7`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 10 + // NEGATIVE + // T has 'struct' constraint BUT + // P has 'interface-type' constraint + .method public hidebysig static void Test10() cil managed + { + + .maxstack 1 + newobj instance void class G8`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 11 + // NEGATIVE + // T has 'new' constraint BUT + // P has 'class-type' constraint + // Since constraints are not inherited this is a negative test because P doesn't have new constraint + // and since not all reference types have default ctor we do not accept this constraint. + .method public hidebysig static void Test11() cil managed + { + + .maxstack 1 + newobj instance void class G9`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 12 + // NEGATIVE + // T has 'new' constraint BUT + // P has 'class' constraint + .method public hidebysig static void Test12() cil managed + { + + .maxstack 1 + newobj instance void class G10`1::.ctor() + pop + ret + } + + + // ===================================================================== + + // TEST 13 + // NEGATIVE + // T has 'new' constraint BUT + // P has 'interface-type' constraint + .method public hidebysig static void Test13() cil managed + { + + .maxstack 1 + newobj instance void class G11`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 14 + // NEGATIVE + // T has 'struct' constraint BUT + // P has 'System.ValueType' constraint + .method public hidebysig static void Test14() cil managed + { + + .maxstack 1 + newobj instance void class G12`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 15 + // NEGATIVE + // T has 'struct'Nullable' constraint + .method public hidebysig static void Test15() cil managed + { + + .maxstack 1 + newobj instance void class G12`1>::.ctor() + pop + ret + } + +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg2.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg2.ilproj new file mode 100644 index 0000000000..c77596dbb6 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg2.ilproj @@ -0,0 +1,38 @@ + + + + + RunTestNeg2 + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg3.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg3.il new file mode 100644 index 0000000000..403c9f1505 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg3.il @@ -0,0 +1,484 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +// See test descriptions below + +.assembly extern mscorlib {} + +.assembly RunTestNeg3 {} + + +.class public auto ansi beforefieldinit A + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public sequential ansi sealed beforefieldinit S + extends [mscorlib]System.ValueType + implements I +{ + .pack 0 + .size 1 +} + + + + +.class interface public abstract auto ansi I {} + + + +.class interface public abstract auto ansi IClass`1 {} + +.class interface public abstract auto ansi IStruct`1 {} + +.class interface public abstract auto ansi INew`1<.ctor T> {} + +// ============================================================ + + +.class private auto ansi beforefieldinit G1`1 + extends [mscorlib]System.Object + implements class IClass`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +.class private auto ansi beforefieldinit G2`1<(I) P> + extends [mscorlib]System.Object + implements class IClass`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class private auto ansi beforefieldinit G3`1<([mscorlib]System.Object) P> + extends [mscorlib]System.Object + implements class IClass`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class private auto ansi beforefieldinit G4`1<([mscorlib]System.ValueType) P> + extends [mscorlib]System.Object + implements class IClass`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +.class private auto ansi beforefieldinit G5`1<([mscorlib]System.Enum) P> + extends [mscorlib]System.Object + implements class IClass`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + // ============================================================ + +.class private auto ansi beforefieldinit G6`1 + extends [mscorlib]System.Object + implements class IStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class private auto ansi beforefieldinit G7`1<(A) P> + extends [mscorlib]System.Object + implements class IStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +.class private auto ansi beforefieldinit G8`1<(I) P> + extends [mscorlib]System.Object + implements class IStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +.class private auto ansi beforefieldinit G12`1<(System.ValueType) P> + extends [mscorlib]System.Object + implements class IStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class private auto ansi beforefieldinit G13`1<(valuetype [mscorlib]System.'Nullable`1') P> + extends [mscorlib]System.Object + implements class IStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + // ============================================================ + +.class public auto ansi beforefieldinit G9`1<(A) P> + extends [mscorlib]System.Object + implements class INew`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit G10`1 + extends [mscorlib]System.Object + implements class INew`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit G11`1<(I) P> + extends [mscorlib]System.Object + implements class INew`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + + + // ============================================================ + +.class public auto ansi beforefieldinit RunTest + extends [mscorlib]System.Object +{ + + // TEST 1 + // NEGATIVE + // T has 'class' constraint BUT + // P has 'struct' constraint + // use a class as type param + .method public hidebysig static void Test1() cil managed + { + + .maxstack 1 + newobj instance void class G1`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 2 + // NEGATIVE + // T has 'class' constraint BUT + // P has 'struct' constraint + // use a struct as type param + .method public hidebysig static void Test2() cil managed + { + + .maxstack 1 + newobj instance void class G1`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 3 + // NEGATIVE + // T has 'class' constraint BUT + // P has interface-type constraint + // This is a secondary constraint - this tells us nothing about the eventual instantiation that + // we can use here. + + .method public hidebysig static void Test3() cil managed + { + + .maxstack 1 + newobj instance void class G2`1::.ctor() + pop + ret + } + + + // ===================================================================== + + // TEST 4 + // NEGATIVE + // T has 'class' constraint BUT + // P has System.Object constraint + .method public hidebysig static void Test4() cil managed + { + + .maxstack 1 + newobj instance void class G3`1::.ctor() + pop + ret + } + + + // ===================================================================== + + // TEST 5 + // NEGATIVE + // T has 'class' constraint BUT + // P has System.ValueType constraint + .method public hidebysig static void Test5() cil managed + { + + .maxstack 1 + newobj instance void class G4`1::.ctor() + pop + ret + } + + + // ===================================================================== + + // TEST 6 + // NEGATIVE + // T has 'class' constraint BUT + // P has System.Enum constraint + .method public hidebysig static void Test6() cil managed + { + + .maxstack 1 + newobj instance void class G5`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 7 + // NEGATIVE + // T has 'struct' constraint BUT + // P has 'class' constraint + // instantiated with a class + .method public hidebysig static void Test7() cil managed + { + + .maxstack 1 + newobj instance void class G6`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 8 + // NEGATIVE + // T has 'struct' constraint BUT + // P has 'class' constraint + // instantiated with a struct + .method public hidebysig static void Test8() cil managed + { + + .maxstack 1 + newobj instance void class G6`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 9 + // NEGATIVE + // T has 'struct' constraint BUT + // P has 'class-type' constraint + .method public hidebysig static void Test9() cil managed + { + + .maxstack 1 + newobj instance void class G7`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 10 + // NEGATIVE + // T has 'struct' constraint BUT + // P has 'interface-type' constraint + .method public hidebysig static void Test10() cil managed + { + + .maxstack 1 + newobj instance void class G8`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 11 + // NEGATIVE + // T has 'new' constraint BUT + // P has 'class-type' constraint + // Since constraints are not inherited this is a negative test because P doesn't have new constraint + // and since not all reference types have default ctor we do not accept this constraint. + .method public hidebysig static void Test11() cil managed + { + + .maxstack 1 + newobj instance void class G9`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 12 + // NEGATIVE + // T has 'new' constraint BUT + // P has 'class' constraint + .method public hidebysig static void Test12() cil managed + { + + .maxstack 1 + newobj instance void class G10`1::.ctor() + pop + ret + } + + + // ===================================================================== + + // TEST 13 + // NEGATIVE + // T has 'new' constraint BUT + // P has 'interface-type' constraint + .method public hidebysig static void Test13() cil managed + { + + .maxstack 1 + newobj instance void class G11`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 14 + // NEGATIVE + // T has 'struct' constraint BUT + // P has 'System.ValueType' constraint + .method public hidebysig static void Test14() cil managed + { + + .maxstack 1 + newobj instance void class G12`1::.ctor() + pop + ret + } + + // ===================================================================== + + // TEST 15 + // NEGATIVE + // T has 'struct'Nullable' constraint + .method public hidebysig static void Test15() cil managed + { + + .maxstack 1 + newobj instance void class G12`1>::.ctor() + pop + ret + } +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg3.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg3.ilproj new file mode 100644 index 0000000000..c7845e854a --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/RunTestNeg3.ilproj @@ -0,0 +1,38 @@ + + + + + RunTestNeg3 + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Secondary_Ctor_Constraints_Type_Negative.cs b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Secondary_Ctor_Constraints_Type_Negative.cs new file mode 100644 index 0000000000..769235f9a3 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Secondary_Ctor_Constraints_Type_Negative.cs @@ -0,0 +1,208 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// NEGATIVE TESTS +/* + +The following constraint combinations are tested: + +- Interface-type, New() +- class, Interface-type, New() +- struct, Interface-type, New() +- Class-type, Interface-type, New() +- Class-type, New() + + +Each is tested with type parameter (whichever is valid in negative tests): +- Class with default nullary ctor (Generic/Non generic) +- Class with no default nullary ctor (Generic/Non generic) +- Class from mscorlib with default nullary ctor +- Abstract Class from mscorlib with no default nullary ctor + +- Struct from mscorlib (Generic/Non generic) +- Struct (Generic/Non generic) +- Enum (Generic/Non generic) + +- Interface (Generic/Non generic) + +- Array + +- Delegate + +- Nullable +*/ + +using System; +using System.Security; + +public class Test +{ + static bool pass; + static int testNumber = 1; + + delegate void Case(); + + + static void Check(Case mytest, string testName, string violatingType, string type) + { + + Console.Write("Test"+testNumber + ": " + testName); + ++testNumber; + + + try + { + mytest(); + + Console.WriteLine("\nFAIL: Did not catch expected TypeLoadException"); + pass = false; + } + catch (TypeLoadException e) + { + // Unhandled Exception: System.TypeLoadException: %0, '%1', on '%2' + // violates the constraint of type parameter '%3'. + + Test.CheckTypeLoadExceptionMessage(8310, e, violatingType, type); + } + + catch (Exception e) + { + Console.WriteLine("\nFAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + + public static void CheckTypeLoadExceptionMessage(uint ResourceID, TypeLoadException e, string violatingType, string type ) + { + if ( + !e.ToString().Contains("0") || + !e.ToString().Contains(violatingType) || + !e.ToString().Contains(type) || + !e.ToString().Contains("T")) + { + Console.WriteLine("Exception message is incorrect"); + pass = false; + } + else + { + Console.WriteLine("Caught expected exception"); + } + } + + + + + public static int Main() + { + pass = true; + + Console.WriteLine("\nNEGATIVE TESTS"); + + Console.WriteLine("\nType: A where T : I, new()\n"); + + + Check(new Case(Interface_DefaultCtorConstraint.Test1), "Generic argument is a class with no default ctor", "ClassNoCtor", "A`1[T]"); + Check(new Case(Interface_DefaultCtorConstraint .Test2), "Generic argument is an mscorlib class with default ctor", "System.Object", "A`1[T]"); + Check(new Case(Interface_DefaultCtorConstraint.Test3), "Generic argument is a delegate", "Delegate1", "A`1[T]"); + Check(new Case(Interface_DefaultCtorConstraint .Test4), "Generic argument is an enum", "Enum1", "A`1[T]"); + Check(new Case(Interface_DefaultCtorConstraint.Test5), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "A`1[T]"); + Check(new Case(Interface_DefaultCtorConstraint.Test6), "Generic argument is an interface with no default ctor", "NonGenInterface", "A`1[T]"); + + Check(new Case(Interface_DefaultCtorConstraint.Test7), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "A`1[T]"); + + Check(new Case(Interface_DefaultCtorConstraint.Test8), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "A`1[T]"); + Check(new Case(Interface_DefaultCtorConstraint.Test9), "Generic argument is a generic interface", "GenInterface[System.Int32]", "A`1[T]"); + Check(new Case(Interface_DefaultCtorConstraint.Test10), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "A`1[T]"); + + Console.WriteLine("\nType: A where T : class, I, new() \n"); + + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test1), "Generic argument is a class with no default ctor", "ClassNoCtor", "D`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test2), "Generic argument is an mscorlib class with default ctor", "System.Object", "D`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test3), "Generic argument is a delegate", "Delegate1", "D`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test4), "Generic argument is an enum", "Enum1", "D`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test5), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "D`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test6), "Generic argument is an interface with no default ctor", "NonGenInterface", "D`1[T]"); + + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test7), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "D`1[T]"); + + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test8), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "D`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test9), "Generic argument is a generic interface", "GenInterface[System.Int32]", "D`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test10), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "D`1[T]"); + + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test11), "Generic argument is a struct", "NonGenStruct", "D`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassConstraint.Test12), "Generic argument is a generic struct", "GenStruct[System.Int32]", "D`1[T]"); + + + Console.WriteLine("\nType: A where T : struct, I, new()\n"); + + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test1), "Generic argument is a class with default ctor", "ClassWithCtor", "E`1[T]"); + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "E`1[T]"); + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test3), "Generic argument is an mscorlib class with default ctor", "System.Object", "E`1[T]"); + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test4), "Generic argument is a delegate", "Delegate1", "E`1[T]"); + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test5), "Generic argument is an enum", "Enum1", "E`1[T]"); + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "E`1[T]"); + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "E`1[T]"); + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test8), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "E`1[T]"); + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test9), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "E`1[T]"); + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test10), "Generic argument is a generic interface", "GenInterface[System.Int32]", "E`1[T]"); + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test11), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "E`1[T]"); + Check(new Case(Interface_DefaultCtorAndStructConstraint.Test12), "Generic argument is a generic class with default ctor", "GenClassWithCtor[System.Int32]", "E`1[T]"); + + + Console.WriteLine("\nType: A where T : C, I, new()\n"); + + + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test1), "Generic argument is a class with default ctor, implements I, doesn't extend C", "ClassWithCtor", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test15), "Generic argument is a class with default ctor, doesn't implement I but extends C", "ClassWithCtor2", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test3), "Generic argument is an mscorlib class with default ctor", "System.Object", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test4), "Generic argument is a delegate", "Delegate1", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test5), "Generic argument is an enum", "Enum1", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test8), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test9), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test10), "Generic argument is a generic interface", "GenInterface[System.Int32]", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test11), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test12), "Generic argument is a generic class with default ctor", "GenClassWithCtor[System.Int32]", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test13), "Generic argument is a struct", "NonGenStruct", "F`1[T]"); + Check(new Case(Interface_DefaultCtorAndClassTypeConstraint.Test14), "Generic argument is a generic struct", "GenStruct[System.Int32]", "F`1[T]"); + + + + Console.WriteLine("\nType: A where T : C, new()\n"); + + + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test1), "Generic argument is a class with default ctor, implements I, doesn't extend C", "ClassWithCtor", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test3), "Generic argument is an mscorlib class with default ctor", "System.Object", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test4), "Generic argument is a delegate", "Delegate1", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test5), "Generic argument is an enum", "Enum1", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test8), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test9), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test10), "Generic argument is a generic interface", "GenInterface[System.Int32]", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test11), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test12), "Generic argument is a generic class with default ctor", "GenClassWithCtor[System.Int32]", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test13), "Generic argument is a struct", "NonGenStruct", "F`1[T]"); + Check(new Case(Instantiation_DefaultCtorAndClassTypeConstraint.Test14), "Generic argument is a generic struct", "GenStruct[System.Int32]", "F`1[T]"); + + + if (pass) + { + Console.WriteLine("PASS"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + } +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Secondary_Ctor_Constraints_Type_Negative.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Secondary_Ctor_Constraints_Type_Negative.csproj new file mode 100644 index 0000000000..40544b9c25 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/Secondary_Ctor_Constraints_Type_Negative.csproj @@ -0,0 +1,48 @@ + + + + + Secondary_Ctor_Constraints_Type_Negative + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_ClassConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_ClassConstraint_Neg.il new file mode 100644 index 0000000000..d7aa60f65f --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_ClassConstraint_Neg.il @@ -0,0 +1,93 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticField_ClassConstraint_Neg {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit B`1 + extends [mscorlib]System.Object +{ + + .field public static int32 i + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SF_ClassConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an enum with no default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1::i + pop + + ret + } +} + +.class public auto ansi beforefieldinit SF_ClassConstraintGenTypes + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1>::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1>::i + pop + + ret + } +} + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_ClassConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_ClassConstraint_Neg.ilproj new file mode 100644 index 0000000000..45854bf958 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_ClassConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + StaticField_ClassConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_Constraints_Neg.cs b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_Constraints_Neg.cs new file mode 100644 index 0000000000..a873c899f0 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_Constraints_Neg.cs @@ -0,0 +1,187 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/* Test various combinations of constraints with illegal parameter types accessing static field of the generic type + +CONSTRAINTS: + +default ctor +reference type +valuetype +default ctor, reference tyoe +default ctor, valuetype + +Test each constraint with (whichever applies to negative tests) +- Class with default nullary ctor (Generic/Non generic) +- Class with no default nullary ctor (Generic/Non generic) +- Class from mscorlib with default nullary ctor +- Abstract Class from mscorlib with no default nullary ctor + +- Struct from mscorlib (Generic/Non generic) +- Struct (Generic/Non generic) +- Enum (Generic/Non generic) + +- Interface (Generic/Non generic) + +- Array + +- Delegate + +- Nullable + +*/ + +using System; + + +public class Test +{ + static bool pass; + static int testNumber = 1; + + delegate void Case(); + + + static void Check(Case mytest, string testName, string violatingType, string type) + { + + Console.Write("Test"+testNumber + ": " + testName); + ++testNumber; + + + try + { + mytest(); + + Console.WriteLine("\nFAIL: Did not catch expected TypeLoadException"); + pass = false; + } + catch (TypeLoadException e) + { + // Unhandled Exception: System.TypeLoadException: %0, '%1', on '%2' + // violates the constraint of type parameter '%3'. + + Test.CheckTypeLoadExceptionMessage(8310, e, violatingType, type); + } + + catch (Exception e) + { + Console.WriteLine("\nFAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + + public static void CheckTypeLoadExceptionMessage(uint ResourceID, TypeLoadException e, string violatingType, string type ) + { + if ( + !e.ToString().Contains("0") || + !e.ToString().Contains(violatingType) || + !e.ToString().Contains(type) || + !e.ToString().Contains("T")) + { + Console.WriteLine("Exception message is incorrect"); + pass = false; + } + else + { + Console.WriteLine("Caught expected exception"); + } + } + + public static int Main() + { + pass = true; + + Console.WriteLine("\nType: A where T : new()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(SF_DefaultCtorConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "A`1[T]"); + Check(new Case(SF_DefaultCtorConstraint.Test4), "Generic argument is a delegate", "Delegate1", "A`1[T]"); + Check(new Case(SF_DefaultCtorConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "A`1[T]"); + Check(new Case(SF_DefaultCtorConstraint.Test7), "Generic argument is an interface with no default ctor", "NonGenInterface", "A`1[T]"); + Check(new Case(SF_DefaultCtorConstraint.Test9), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "A`1[T]"); + Check(new Case(SF_DefaultCtorConstraintGenTypes.Test2), " Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "A`1[T]"); + Check(new Case(SF_DefaultCtorConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "A`1[T]"); + + + Console.WriteLine("\nType: A where T : class()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(SF_ClassConstraint.Test3), "Generic argument is a struct", "NonGenStruct", "B`1[T]"); + Check(new Case(SF_ClassConstraint.Test8), "Generic argument is an enum", "Enum1", "B`1[T]"); + Check(new Case(SF_ClassConstraintGenTypes.Test3), "Generic argument is a generic struct with default ctor", "GenStruct[System.Int32]", "B`1[T]"); + Check(new Case(SF_ClassConstraintGenTypes.Test6), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "B`1[T]"); + + Console.WriteLine("\nType: A where T : struct()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(SF_StructConstraint.Test1), "Generic argument is a class with default ctor", "ClassWithCtor", "C`1[T]"); + Check(new Case(SF_StructConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "C`1[T]"); + Check(new Case(SF_StructConstraint.Test4), "Generic argument is a delegate", "Delegate1", "C`1[T]"); + Check(new Case(SF_StructConstraint.Test5), "Generic argument is an mscorlib class with default ctor", "System.Object", "C`1[T]"); + Check(new Case(SF_StructConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "C`1[T]"); + Check(new Case(SF_StructConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "C`1[T]"); + Check(new Case(SF_StructConstraint.Test10), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "C`1[T]"); + + Check(new Case(SF_StructConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor", "GenClassWithCtor[System.Int32]", "C`1[T]"); + Check(new Case(SF_StructConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "C`1[T]"); + Check(new Case(SF_StructConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "C`1[T]"); + Check(new Case(SF_StructConstraintGenTypes.Test7), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "C`1[T]"); + + + Console.WriteLine("\nType: A where T : class(), new() \n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(SF_DefaultCtorAndClassConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "D`1[T]"); + Check(new Case(SF_DefaultCtorAndClassConstraint.Test3), "Generic argument is a struct", "NonGenStruct", "D`1[T]"); + Check(new Case(SF_DefaultCtorAndClassConstraint.Test4), "Generic argument is a delegate", "Delegate1", "D`1[T]"); + Check(new Case(SF_DefaultCtorAndClassConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "D`1[T]"); + Check(new Case(SF_DefaultCtorAndClassConstraint.Test9), "Generic argument is an mscorlib struct", "System.DateTime", "D`1[T]"); + Check(new Case(SF_DefaultCtorAndClassConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "D`1[T]"); + Check(new Case(SF_DefaultCtorAndClassConstraint.Test8), "Generic argument is an enum", "Enum1", "D`1[T]"); + Check(new Case(SF_DefaultCtorAndClassConstraint.Test10), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "D`1[T]"); + + + Check(new Case(SF_DefaultCtorAndClassConstraintGenTypes.Test3), "Generic argument is a generic struct", "GenStruct[System.Int32]", "D`1[T]"); + Check(new Case(SF_DefaultCtorAndClassConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "D`1[T]"); + Check(new Case(SF_DefaultCtorAndClassConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "D`1[T]"); + Check(new Case(SF_DefaultCtorAndClassConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct", "System.Collections.Generic.KeyValuePair`2[NonGenStruct,System.Int32]", "D`1[T]"); + Check(new Case(SF_DefaultCtorAndClassConstraintGenTypes.Test7), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "D`1[T]"); + + + Console.WriteLine("\nType: A where T : struct(), new()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(SF_DefaultCtorAndStructConstraint.Test1), "Generic argument is a class with default ctor", "ClassWithCtor", "E`1[T]"); + Check(new Case(SF_DefaultCtorAndStructConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "E`1[T]"); + Check(new Case(SF_DefaultCtorAndStructConstraint.Test4), "Generic argument is a delegate", "Delegate1", "E`1[T]"); + Check(new Case(SF_DefaultCtorAndStructConstraint.Test5), "Generic argument is an mscorlib class with default ctor", "System.Object", "E`1[T]"); + Check(new Case(SF_DefaultCtorAndStructConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "E`1[T]"); + Check(new Case(SF_DefaultCtorAndStructConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "E`1[T]"); + + Check(new Case(SF_DefaultCtorAndStructConstraint.Test10), "Generic argument is an array of classes with default ctor", "NonGenStruct[]", "E`1[T]"); + + + Check(new Case(SF_DefaultCtorAndStructConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor", "GenClassWithCtor[System.Int32]", "E`1[T]"); + Check(new Case(SF_DefaultCtorAndStructConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "E`1[T]"); + Check(new Case(SF_DefaultCtorAndStructConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "E`1[T]"); + Check(new Case(SF_DefaultCtorAndStructConstraintGenTypes.Test7), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "E`1[T]"); + + + if (pass) + { + Console.WriteLine("PASS"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + } +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_Constraints_Neg.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_Constraints_Neg.csproj new file mode 100644 index 0000000000..da81447f11 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_Constraints_Neg.csproj @@ -0,0 +1,48 @@ + + + + + StaticField_Constraints_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndClassConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndClassConstraint_Neg.il new file mode 100644 index 0000000000..038ca345c6 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndClassConstraint_Neg.il @@ -0,0 +1,218 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticField_DefaultCtorAndClassConstraint_Neg {} + + +// Generic class with class() and new() constraints +.class public auto ansi beforefieldinit D`1 + extends [mscorlib]System.Object +{ + + .field public static int32 i + + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + + + +} + +.class public auto ansi beforefieldinit SF_DefaultCtorAndClassConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1::i + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a delegate (doesn't have public parameterless constructor) + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + ldsfld int32 class D`1::i + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an enum + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib struct + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1::i + pop + + ret + } + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1::i + pop + + ret + } + + + +} + +.class public auto ansi beforefieldinit SF_DefaultCtorAndClassConstraintGenTypes + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1>::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a generic struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1>::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an generic interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1>::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib generic struct + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + ldsfld int32 class D`1>::i + + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1>::i + pop + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndClassConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndClassConstraint_Neg.ilproj new file mode 100644 index 0000000000..f2ad4d0df3 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndClassConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + StaticField_DefaultCtorAndClassConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndStructConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndStructConstraint_Neg.il new file mode 100644 index 0000000000..8c1743f6c3 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndStructConstraint_Neg.il @@ -0,0 +1,181 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticField_DefaultCtorAndStructConstraint_Neg {} + + +// Generic class with struct() and new() constraints +.class public auto ansi beforefieldinit E`1 + extends [mscorlib]System.Object +{ + + .field public static int32 i + + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SF_DefaultCtorAndStructConstraint + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1::i + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a delegate + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + ldsfld int32 class E`1::i + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1::i + pop + + ret + } +} + +.class public auto ansi beforefieldinit SF_DefaultCtorAndStructConstraintGenTypes + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1>::i + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1>::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1>::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1>::i + pop + + ret + } +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndStructConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndStructConstraint_Neg.ilproj new file mode 100644 index 0000000000..768aa07c45 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorAndStructConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + StaticField_DefaultCtorAndStructConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorConstraint_Neg.il new file mode 100644 index 0000000000..9f801f901a --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorConstraint_Neg.il @@ -0,0 +1,131 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticField_DefaultCtorConstraint_Neg {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit A`1<.ctor T> + extends [mscorlib]System.Object +{ + + .field public static int32 i + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit SF_DefaultCtorConstraint + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a delegate (doesn't have public parameterless constructor) + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1::i + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1::i + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1::i + pop + + ret + } +} + +.class public auto ansi beforefieldinit SF_DefaultCtorConstraintGenTypes + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1>::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1>::i + pop + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorConstraint_Neg.ilproj new file mode 100644 index 0000000000..e8b47315cf --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_DefaultCtorConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + StaticField_DefaultCtorConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_StructConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_StructConstraint_Neg.il new file mode 100644 index 0000000000..061256f5bc --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_StructConstraint_Neg.il @@ -0,0 +1,179 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticField_StructConstraint_Neg {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit C`1 + extends [mscorlib]System.Object +{ + .field public static int32 i + + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SF_StructConstraint + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1::i + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1::i + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a delegate + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1::i + pop + + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + ldsfld int32 class C`1::i + pop + ret + } + + + // NEGATIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1::i + pop + + ret + } +} + +.class public auto ansi beforefieldinit SF_StructConstraintGenTypes + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1>::i + pop + + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1>::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1>::i + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1>::i + pop + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_StructConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_StructConstraint_Neg.ilproj new file mode 100644 index 0000000000..c883ffdbb6 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticField_StructConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + StaticField_StructConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_ClassConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_ClassConstraint_Neg.il new file mode 100644 index 0000000000..e1b19d019a --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_ClassConstraint_Neg.il @@ -0,0 +1,87 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticMethod_ClassConstraint_Neg {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit B`1 + extends [mscorlib]System.Object +{ + + .method public static hidebysig void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SM_ClassConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + call void class B`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an enum with no default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + call void class B`1::method1() + ret + } +} + +.class public auto ansi beforefieldinit SM_ClassConstraintGenTypes + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + call void class B`1>::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + call void class B`1>::method1() + ret + } +} + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_ClassConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_ClassConstraint_Neg.ilproj new file mode 100644 index 0000000000..6a671d9102 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_ClassConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + StaticMethod_ClassConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_Constraints_Neg.cs b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_Constraints_Neg.cs new file mode 100644 index 0000000000..4bb2c78bb0 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_Constraints_Neg.cs @@ -0,0 +1,181 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/* Test various combinations of constraints with illegal parameter types by invoking static method on the generic type +CONSTRAINTS: + +default ctor +reference type +valuetype +default ctor, reference tyoe +default ctor, valuetype + +Test each constraint with (whichever applies to negative testing) +- Class with default nullary ctor (Generic/Non generic) +- Class with no default nullary ctor (Generic/Non generic) +- Class from mscorlib with default nullary ctor +- Abstract Class from mscorlib with no default nullary ctor + +- Struct from mscorlib (Generic/Non generic) +- Struct (Generic/Non generic) +- Enum (Generic/Non generic) + +- Interface (Generic/Non generic) + +- Array + +- Delegate + +- Nullable +*/ + +using System; + + +public class Test +{ + static bool pass; + static int testNumber = 1; + + delegate void Case(); + + + static void Check(Case mytest, string testName, string violatingType, string type) + { + + Console.Write("Test"+testNumber + ": " + testName); + ++testNumber; + + + try + { + mytest(); + + Console.WriteLine("\nFAIL: Did not catch expected TypeLoadException"); + pass = false; + } + catch (TypeLoadException e) + { + // Unhandled Exception: System.TypeLoadException: %0, '%1', on '%2' + // violates the constraint of type parameter '%3'. + + Test.CheckTypeLoadExceptionMessage(8310, e, violatingType, type); + } + + catch (Exception e) + { + Console.WriteLine("\nFAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + + public static void CheckTypeLoadExceptionMessage(uint ResourceID, TypeLoadException e, string violatingType, string type ) + { + if ( + !e.ToString().Contains("0") || + !e.ToString().Contains(violatingType) || + !e.ToString().Contains(type) || + !e.ToString().Contains("T")) + { + Console.WriteLine("Exception message is incorrect"); + pass = false; + } + else + { + Console.WriteLine("Caught expected exception"); + } + } + + + public static int Main() + { + pass = true; + + Console.WriteLine("\nType: A where T : new()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(SM_DefaultCtorConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "A`1[T]"); + Check(new Case(SM_DefaultCtorConstraint.Test4), "Generic argument is a delegate", "Delegate1", "A`1[T]"); + Check(new Case(SM_DefaultCtorConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "A`1[T]"); + Check(new Case(SM_DefaultCtorConstraint.Test7), "Generic argument is an interface with no default ctor", "NonGenInterface", "A`1[T]"); + Check(new Case(SM_DefaultCtorConstraint.Test9), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "A`1[T]"); + Check(new Case(SM_DefaultCtorConstraintGenTypes.Test2), " Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "A`1[T]"); + Check(new Case(SM_DefaultCtorConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "A`1[T]"); + + + Console.WriteLine("\nType: A where T : class()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(SM_ClassConstraint.Test3), "Generic argument is a struct", "NonGenStruct", "B`1[T]"); + Check(new Case(SM_ClassConstraint.Test8), "Generic argument is an enum", "Enum1", "B`1[T]"); + Check(new Case(SM_ClassConstraintGenTypes.Test3), "Generic argument is a generic struct with default ctor", "GenStruct[System.Int32]", "B`1[T]"); + Check(new Case(SM_ClassConstraintGenTypes.Test6), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "B`1[T]"); + + Console.WriteLine("\nType: A where T : struct()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(SM_StructConstraint.Test1), "Generic argument is a class with default ctor", "ClassWithCtor", "C`1[T]"); + Check(new Case(SM_StructConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "C`1[T]"); + Check(new Case(SM_StructConstraint.Test4), "Generic argument is a delegate", "Delegate1", "C`1[T]"); + Check(new Case(SM_StructConstraint.Test5), "Generic argument is an mscorlib class with default ctor", "System.Object", "C`1[T]"); + Check(new Case(SM_StructConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "C`1[T]"); + Check(new Case(SM_StructConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "C`1[T]"); + Check(new Case(SM_StructConstraint.Test10), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "C`1[T]"); + Check(new Case(SM_StructConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor", "GenClassWithCtor[System.Int32]", "C`1[T]"); + Check(new Case(SM_StructConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "C`1[T]"); + Check(new Case(SM_StructConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "C`1[T]"); + Check(new Case(SM_StructConstraintGenTypes.Test7), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "C`1[T]"); + + + + Console.WriteLine("\nType: A where T : class(), new() \n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(SM_DefaultCtorAndClassConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraint.Test3), "Generic argument is a struct", "NonGenStruct", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraint.Test4), "Generic argument is a delegate", "Delegate1", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraint.Test9), "Generic argument is an mscorlib struct", "System.DateTime", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraint.Test8), "Generic argument is an enum", "Enum1", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraint.Test10), "Generic argument is an array of classes with default ctor", "ClassWithCtor[]", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraintGenTypes.Test3), "Generic argument is a generic struct", "GenStruct[System.Int32]", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct", "System.Collections.Generic.KeyValuePair`2[NonGenStruct,System.Int32]", "D`1[T]"); + Check(new Case(SM_DefaultCtorAndClassConstraintGenTypes.Test7), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "D`1[T]"); + + + Console.WriteLine("\nType: A where T : struct(), new()\n"); + Console.WriteLine("\nNEGATIVE TESTS"); + + Check(new Case(SM_DefaultCtorAndStructConstraint.Test1), "Generic argument is a class with default ctor", "ClassWithCtor", "E`1[T]"); + Check(new Case(SM_DefaultCtorAndStructConstraint.Test2), "Generic argument is a class with no default ctor", "ClassNoCtor", "E`1[T]"); + Check(new Case(SM_DefaultCtorAndStructConstraint.Test4), "Generic argument is a delegate", "Delegate1", "E`1[T]"); + Check(new Case(SM_DefaultCtorAndStructConstraint.Test5), "Generic argument is an mscorlib class with default ctor", "System.Object", "E`1[T]"); + Check(new Case(SM_DefaultCtorAndStructConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor", "System.ValueType", "E`1[T]"); + Check(new Case(SM_DefaultCtorAndStructConstraint.Test7), "Generic argument is an interface", "NonGenInterface", "E`1[T]"); + Check(new Case(SM_DefaultCtorAndStructConstraint.Test10), "Generic argument is an array of classes with default ctor", "NonGenStruct[]", "E`1[T]"); + Check(new Case(SM_DefaultCtorAndStructConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor", "GenClassWithCtor[System.Int32]", "E`1[T]"); + Check(new Case(SM_DefaultCtorAndStructConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor", "GenClassNoCtor[System.Int32]", "E`1[T]"); + Check(new Case(SM_DefaultCtorAndStructConstraintGenTypes.Test5), "Generic argument is a generic interface", "GenInterface[System.Int32]", "E`1[T]"); + Check(new Case(SM_DefaultCtorAndStructConstraintGenTypes.Test7), "Generic argument is Nullable", "System.Nullable`1[System.Int32]", "E`1[T]"); + + + if (pass) + { + Console.WriteLine("PASS"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + } +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_Constraints_Neg.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_Constraints_Neg.csproj new file mode 100644 index 0000000000..448eb02af5 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_Constraints_Neg.csproj @@ -0,0 +1,48 @@ + + + + + StaticMethod_Constraints_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndClassConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndClassConstraint_Neg.il new file mode 100644 index 0000000000..d9240b906e --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndClassConstraint_Neg.il @@ -0,0 +1,187 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticMethod_DefaultCtorAndClassConstraint_Neg {} + + +// Generic class with class() and new() constraints +.class public auto ansi beforefieldinit D`1 + extends [mscorlib]System.Object +{ + + .method public static hidebysig void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + + + +} + +.class public auto ansi beforefieldinit SM_DefaultCtorAndClassConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + call void class D`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + call void class D`1::method1() + ret + } + + // NEGATIVE TEST + // generic argument is a delegate (doesn't have public parameterless constructor) + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + call void class D`1::method1() + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + call void class D`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + call void class D`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an enum + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + call void class D`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib struct + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + call void class D`1::method1() + ret + } + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + call void class D`1::method1() + ret + } +} + +.class public auto ansi beforefieldinit SM_DefaultCtorAndClassConstraintGenTypes + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + call void class D`1>::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is a generic struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + call void class D`1>::method1() + ret + } + + // NEGATIVE TEST + // generic argument is an generic interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + call void class D`1>::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib generic struct + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + call void class D`1>::method1() + + ret + } + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + call void class D`1>::method1() + ret + } + +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndClassConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndClassConstraint_Neg.ilproj new file mode 100644 index 0000000000..d1fbfe1331 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndClassConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + StaticMethod_DefaultCtorAndClassConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndStructConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndStructConstraint_Neg.il new file mode 100644 index 0000000000..a09efce3f5 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndStructConstraint_Neg.il @@ -0,0 +1,162 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticMethod_DefaultCtorAndStructConstraint_Neg {} + + +// Generic class with struct() and new() constraints +.class public auto ansi beforefieldinit E`1 + extends [mscorlib]System.Object +{ + + .method public static hidebysig void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SM_DefaultCtorAndStructConstraint + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + call void class E`1::method1() + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + call void class E`1::method1() + ret + } + + // NEGATIVE TEST + // generic argument is a delegate + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + call void class E`1::method1() + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + call void class E`1::method1() + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + call void class E`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + call void class E`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + call void class E`1::method1() + ret + } +} + +.class public auto ansi beforefieldinit SM_DefaultCtorAndStructConstraintGenTypes + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + call void class E`1>::method1() + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + call void class E`1>::method1() + ret + } + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + call void class E`1>::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + call void class E`1>::method1() + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndStructConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndStructConstraint_Neg.ilproj new file mode 100644 index 0000000000..75978bb441 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorAndStructConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + StaticMethod_DefaultCtorAndStructConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorConstraint_Neg.il new file mode 100644 index 0000000000..c8adac64cd --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorConstraint_Neg.il @@ -0,0 +1,123 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticMethod_DefaultCtorConstraint_Neg {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit A`1<.ctor T> + extends [mscorlib]System.Object +{ + + .method public static hidebysig void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit SM_DefaultCtorConstraint + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + call void class A`1::method1() + + ret + } + + // NEGATIVE TEST + // generic argument is a delegate (doesn't have public parameterless constructor) + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + call void class A`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + call void class A`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + call void class A`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + call void class A`1::method1() + + ret + } +} + +.class public auto ansi beforefieldinit SM_DefaultCtorConstraintGenTypes + extends [mscorlib]System.Object +{ + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + call void class A`1>::method1() + ret + } + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + call void class A`1>::method1() + ret + } +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorConstraint_Neg.ilproj new file mode 100644 index 0000000000..2ebd8251c4 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_DefaultCtorConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + StaticMethod_DefaultCtorConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_StructConstraint_Neg.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_StructConstraint_Neg.il new file mode 100644 index 0000000000..675639320d --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_StructConstraint_Neg.il @@ -0,0 +1,162 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticMethod_StructConstraint_Neg {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit C`1 + extends [mscorlib]System.Object +{ + + .method public static hidebysig void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SM_StructConstraint + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + call void class C`1::method1() + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + call void class C`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is a delegate + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + call void class C`1::method1() + ret + } + + // NEGATIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + call void class C`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + call void class C`1::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + call void class C`1::method1() + ret + } + + // NEGATIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + call void class C`1::method1() + ret + } +} + +.class public auto ansi beforefieldinit SM_StructConstraintGenTypes + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + call void class C`1>::method1() + ret + } + + // NEGATIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + call void class C`1>::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is an interface + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + call void class C`1>::method1() + ret + } + + + // NEGATIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + call void class C`1>::method1() + + ret + } +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_StructConstraint_Neg.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_StructConstraint_Neg.ilproj new file mode 100644 index 0000000000..e578d8ed7e --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/StaticMethod_StructConstraint_Neg.ilproj @@ -0,0 +1,38 @@ + + + + + StaticMethod_StructConstraint_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam2_Constraints_Neg.cs b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam2_Constraints_Neg.cs new file mode 100644 index 0000000000..abe962b409 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam2_Constraints_Neg.cs @@ -0,0 +1,121 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/* Test various combinations of constraints with illegal parameter types by instantiating the type + +*/ + +using System; + + + +public class Test +{ + static bool pass; + static int testNumber = 1; + + delegate void Case(); + + + static void Check(Case mytest, string testName, string genArgNumber, string violatingType, string type, string typeParam) + { + + Console.Write("Test"+testNumber + ": " + testName); + ++testNumber; + + + try + { + mytest(); + + Console.WriteLine("\nFAIL: Did not catch expected TypeLoadException"); + pass = false; + } + catch (TypeLoadException e) + { + // Unhandled Exception: System.TypeLoadException: %0, '%1', on '%2' + // violates the constraint of type parameter '%3'. + + Test.CheckTypeLoadExceptionMessage(8310, genArgNumber, e, violatingType, type, typeParam); + } + + catch (Exception e) + { + Console.WriteLine("\nFAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + + public static void CheckTypeLoadExceptionMessage(uint ResourceID, string genArgNumber, TypeLoadException e, string violatingType, string type, string typeParam ) + { + if ( + !e.ToString().Contains(genArgNumber) || + !e.ToString().Contains(violatingType) || + !e.ToString().Contains(type) || + !e.ToString().Contains(typeParam)) + { + Console.WriteLine("Exception message is incorrect"); + pass = false; + } + else + { + Console.WriteLine("Caught expected exception"); + } + } + + public static int Main() + { + pass = true; + + Console.WriteLine("\nType: GClass where T : class\n"); + Console.WriteLine("NEGATIVE TESTS"); + + Check(new Case(RunTest.Test1), "class G1

: GClass

where P : struct {}, insantiate with class","0", "P", "GClass`1[T]", "T"); + Check(new Case(RunTest.Test2), "class G1

: GClass

where P : struct {}, instantiate with valuetype", "0", "P", "GClass`1[T]", "T"); + Check(new Case(RunTest.Test3), "class G2

: GClass

where P : I {}", "0", "P", "GClass`1[T]", "T"); + Check(new Case(RunTest.Test4), "class G3

: GClass

where P : System.Object {}", "0", "P", "GClass`1[T]", "T"); + Check(new Case(RunTest.Test5), "class G4

: GClass

where P : System.ValueType {}", "0", "P", "GClass`1[T]", "T"); + Check(new Case(RunTest.Test6), "class G5

: GClass

where P : System.Enum {}", "0", "P", "GClass`1[T]", "T"); + + + Console.WriteLine("\nType: GStruct where T : struct\n"); + Console.WriteLine("NEGATIVE TESTS"); + + + Check(new Case(RunTest.Test7), "class G6

: IStruct

where P : class {}, insantiate with class","0", "P", "GStruct`1[T]", "T"); + Check(new Case(RunTest.Test8), "class G6

: IStruct

where P : class {}, instantiate with valuetype", "0", "P", "GStruct`1[T]", "T"); + Check(new Case(RunTest.Test9), "class G7

: IStruct

where P : A {}", "0", "P", "GStruct`1[T]", "T"); + Check(new Case(RunTest.Test10), "class G8

: IStruct

where P : I {}", "0", "P", "GStruct`1[T]", "T"); + + Check(new Case(RunTest.Test14), "class G12

: IStruct

where P : System.ValueType {}", "0", "P", "GStruct`1[T]", "T"); + Check(new Case(RunTest.Test15), "class G12

: IStruct

where P : System.Nullable {}", "0", "P", "GStruct`1[T]", "T"); + + + Console.WriteLine("\nType: GNew where T : new() \n"); + Console.WriteLine("NEGATIVE TESTS"); + + + Check(new Case(RunTest.Test11), "class G9

: GNew

where P : A {}, insantiate with class","0", "P", "GNew`1[T]", "T"); + Check(new Case(RunTest.Test12), "class G10

: GNew

where P : class {}, instantiate with valuetype", "0", "P", "GNew`1[T]", "T"); + Check(new Case(RunTest.Test13), "class G11

: GNew

where P : I {}", "0", "P", "GNew`1[T]", "T"); + + + + if (pass) + { + Console.WriteLine("PASS"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + } +} + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam2_Constraints_Neg.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam2_Constraints_Neg.csproj new file mode 100644 index 0000000000..eb3a542679 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam2_Constraints_Neg.csproj @@ -0,0 +1,43 @@ + + + + + TypeParam2_Constraints_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam3_Constraints_Neg.cs b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam3_Constraints_Neg.cs new file mode 100644 index 0000000000..275785e70e --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam3_Constraints_Neg.cs @@ -0,0 +1,123 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/* Test various combinations of constraints with illegal parameter types by instantiating the type + These tests are similar to TypeParam2* only here we have a generic interface I with a constraint on T + and in TypeParam2* we have a generic class G with a constraint on T. +*/ + +using System; + + + +public class Test +{ + static bool pass; + static int testNumber = 1; + + delegate void Case(); + + + static void Check(Case mytest, string testName, string genArgNumber, string violatingType, string type, string typeParam) + { + + Console.Write("Test"+testNumber + ": " + testName); + ++testNumber; + + + try + { + mytest(); + + Console.WriteLine("\nFAIL: Did not catch expected TypeLoadException"); + pass = false; + } + catch (TypeLoadException e) + { + // Unhandled Exception: System.TypeLoadException: %0, '%1', on '%2' + // violates the constraint of type parameter '%3'. + + Test.CheckTypeLoadExceptionMessage(8310, genArgNumber, e, violatingType, type, typeParam); + } + + catch (Exception e) + { + Console.WriteLine("\nFAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + + public static void CheckTypeLoadExceptionMessage(uint ResourceID, string genArgNumber, TypeLoadException e, string violatingType, string type, string typeParam ) + { + if ( + !e.ToString().Contains(genArgNumber) || + !e.ToString().Contains(violatingType) || + !e.ToString().Contains(type) || + !e.ToString().Contains(typeParam)) + { + Console.WriteLine("Exception message is incorrect"); + pass = false; + } + else + { + Console.WriteLine("Caught expected exception"); + } + } + + public static int Main() + { + pass = true; + + Console.WriteLine("\nType: IClass where T : class\n"); + Console.WriteLine("NEGATIVE TESTS"); + + Check(new Case(RunTest.Test1), "class G1

: IClass

where P : struct {}, insantiate with class","0", "P", "IClass`1[T]", "T"); + Check(new Case(RunTest.Test2), "class G1

: IClass

where P : struct {}, instantiate with valuetype", "0", "P", "IClass`1[T]", "T"); + Check(new Case(RunTest.Test3), "class G2

: IClass

where P : I {}", "0", "P", "IClass`1[T]", "T"); + Check(new Case(RunTest.Test4), "class G3

: IClass

where P : System.Object {}", "0", "P", "IClass`1[T]", "T"); + Check(new Case(RunTest.Test5), "class G4

: IClass

where P : System.ValueType {}", "0", "P", "IClass`1[T]", "T"); + Check(new Case(RunTest.Test6), "class G5

: IClass

where P : System.Enum {}", "0", "P", "IClass`1[T]", "T"); + + + Console.WriteLine("\nType: IStruct where T : struct\n"); + Console.WriteLine("NEGATIVE TESTS"); + + + Check(new Case(RunTest.Test7), "class G6

: IStruct

where P : class {}, insantiate with class","0", "P", "IStruct`1[T]", "T"); + Check(new Case(RunTest.Test8), "class G6

: IStruct

where P : class {}, instantiate with valuetype", "0", "P", "IStruct`1[T]", "T"); + Check(new Case(RunTest.Test9), "class G7

: IStruct

where P : A {}", "0", "P", "IStruct`1[T]", "T"); + Check(new Case(RunTest.Test10), "class G8

: IStruct

where P : I {}", "0", "P", "IStruct`1[T]", "T"); + + Check(new Case(RunTest.Test14), "class G12

: IStruct

where P : System.ValueType {}", "0", "P", "IStruct`1[T]", "T"); + Check(new Case(RunTest.Test15), "class G12

: IStruct

where P : System.Nullable {}", "0", "P", "IStruct`1[T]", "T"); + + + + Console.WriteLine("\nType: INew where T : new() \n"); + Console.WriteLine("NEGATIVE TESTS"); + + + Check(new Case(RunTest.Test11), "class G9

: INew

where P : A {}, insantiate with class","0", "P", "INew`1[T]", "T"); + Check(new Case(RunTest.Test12), "class G10

: INew

where P : class {}, instantiate with valuetype", "0", "P", "INew`1[T]", "T"); + Check(new Case(RunTest.Test13), "class G11

: INew

where P : I {}", "0", "P", "INew`1[T]", "T"); + + + + if (pass) + { + Console.WriteLine("PASS"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + } +} + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam3_Constraints_Neg.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam3_Constraints_Neg.csproj new file mode 100644 index 0000000000..3eeb38e2a9 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/TypeParam3_Constraints_Neg.csproj @@ -0,0 +1,43 @@ + + + + + TypeParam3_Constraints_Neg + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/app.config b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/app.config new file mode 100644 index 0000000000..e5622f77ad --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/project.json b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/project.json new file mode 100644 index 0000000000..a2e84dc340 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types.il new file mode 100644 index 0000000000..53c0b9e255 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types.il @@ -0,0 +1,117 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} + +.assembly Types {} + +// class with public nullary ctor +.class public auto ansi beforefieldinit ClassWithCtor + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +// generic class with public nullary ctor +.class public auto ansi beforefieldinit GenClassWithCtor + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +// class without public nullary ctor +.class public auto ansi beforefieldinit ClassNoCtor + extends [mscorlib]System.Object +{ +} + +// generic class without public nullary ctor +.class public auto ansi beforefieldinit GenClassNoCtor + extends [mscorlib]System.Object +{ +} + + +// struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit NonGenStruct + extends [mscorlib]System.ValueType +{ + .pack 0 + .size 1 +} + + + +// generic struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit GenStruct + extends [mscorlib]System.ValueType +{ + .pack 0 + .size 1 +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit NonGenInterface +{ +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit GenInterface +{ +} + + +.class public auto ansi sealed Enum1 + extends [mscorlib]System.Enum +{ + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype Enum1 One = int32(0x00000000) +} + + +// doesn't have public parameterless constructor +.class public auto ansi sealed Delegate1 + extends [mscorlib]System.MulticastDelegate +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor(object 'object', + native int 'method') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void Invoke() runtime managed + { + } + + .method public hidebysig newslot virtual + instance class [mscorlib]System.IAsyncResult + BeginInvoke(class [mscorlib]System.AsyncCallback callback, + object 'object') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void EndInvoke(class [mscorlib]System.IAsyncResult result) runtime managed + { + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types.ilproj new file mode 100644 index 0000000000..e90ddd06ea --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types.ilproj @@ -0,0 +1,38 @@ + + + + + types + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI.il new file mode 100644 index 0000000000..56a463547c --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI.il @@ -0,0 +1,131 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} + +.assembly Types_implementI {} + + +.class interface public abstract auto ansi I {} + + +// class with public nullary ctor +.class public auto ansi beforefieldinit ClassWithCtor + extends [mscorlib]System.Object + implements I + +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +// generic class with public nullary ctor +.class public auto ansi beforefieldinit GenClassWithCtor + extends [mscorlib]System.Object + implements I +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +// class without public nullary ctor +.class public auto ansi beforefieldinit ClassNoCtor + extends [mscorlib]System.Object + implements I +{ +} + +// generic class without public nullary ctor +.class public auto ansi beforefieldinit GenClassNoCtor + extends [mscorlib]System.Object + implements I +{ +} + + +// struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit NonGenStruct + extends [mscorlib]System.ValueType + implements I +{ + .pack 0 + .size 1 +} + + + +// generic struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit GenStruct + extends [mscorlib]System.ValueType + implements I +{ + .pack 0 + .size 1 +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit NonGenInterface + implements I +{ +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit GenInterface + implements I +{ +} + + +.class public auto ansi sealed Enum1 + extends [mscorlib]System.Enum +{ + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype Enum1 One = int32(0x00000000) +} + + +// doesn't have public parameterless constructor +.class public auto ansi sealed Delegate1 + extends [mscorlib]System.MulticastDelegate + implements I +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor(object 'object', + native int 'method') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void Invoke() runtime managed + { + } + + .method public hidebysig newslot virtual + instance class [mscorlib]System.IAsyncResult + BeginInvoke(class [mscorlib]System.AsyncCallback callback, + object 'object') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void EndInvoke(class [mscorlib]System.IAsyncResult result) runtime managed + { + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI.ilproj new file mode 100644 index 0000000000..56d5b6ed3e --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI.ilproj @@ -0,0 +1,38 @@ + + + + + types_implementI + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI_extendC.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI_extendC.il new file mode 100644 index 0000000000..68bcbe5c43 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI_extendC.il @@ -0,0 +1,150 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} + +.assembly types_implementI_extendC {} + + +.class interface public abstract auto ansi I {} + +.class public auto ansi beforefieldinit C + extends [mscorlib]System.Object +{} + +// class with public nullary ctor implements I but doesn't extend C +.class public auto ansi beforefieldinit ClassWithCtor + extends [mscorlib]System.Object + implements I + +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +// class with public nullary ctor extends C but doesn't implement I +.class public auto ansi beforefieldinit ClassWithCtor2 + extends C + +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +// generic class with public nullary ctor +.class public auto ansi beforefieldinit GenClassWithCtor + extends [mscorlib]System.Object + implements I +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +// class without public nullary ctor +.class public auto ansi beforefieldinit ClassNoCtor + extends [mscorlib]System.Object + implements I +{ +} + +// generic class without public nullary ctor +.class public auto ansi beforefieldinit GenClassNoCtor + extends [mscorlib]System.Object + implements I +{ +} + + +// struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit NonGenStruct + extends [mscorlib]System.ValueType + implements I +{ + .pack 0 + .size 1 +} + + + +// generic struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit GenStruct + extends [mscorlib]System.ValueType + implements I +{ + .pack 0 + .size 1 +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit NonGenInterface + implements I +{ +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit GenInterface + implements I +{ +} + + +.class public auto ansi sealed Enum1 + extends [mscorlib]System.Enum +{ + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype Enum1 One = int32(0x00000000) +} + + +// doesn't have public parameterless constructor +.class public auto ansi sealed Delegate1 + extends [mscorlib]System.MulticastDelegate + implements I +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor(object 'object', + native int 'method') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void Invoke() runtime managed + { + } + + .method public hidebysig newslot virtual + instance class [mscorlib]System.IAsyncResult + BeginInvoke(class [mscorlib]System.AsyncCallback callback, + object 'object') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void EndInvoke(class [mscorlib]System.IAsyncResult result) runtime managed + { + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI_extendC.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI_extendC.ilproj new file mode 100644 index 0000000000..783be27964 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Negative/types_implementI_extendC.ilproj @@ -0,0 +1,38 @@ + + + + + types_implementI_extendC + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_ClassConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_ClassConstraint_Pos.il new file mode 100644 index 0000000000..cb9ea447e3 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_ClassConstraint_Pos.il @@ -0,0 +1,166 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Instantiation_ClassConstraint_Pos {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit B`1 + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit ClassConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class B`1::.ctor() + pop + + ret + } + + // POSITIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class B`1::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is a delegate + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class B`1::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class B`1::.ctor() + pop + + ret + } + + + + // POSITIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + newobj instance void class B`1::.ctor() + pop + ret + } + + + // POSITIVE TEST + // generic argument is an interface + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + + newobj instance void class B`1::.ctor() + pop + + ret + } + + // POSITIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class B`1::.ctor() + pop + + ret + } + +} + +.class public auto ansi beforefieldinit ClassConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class B`1>::.ctor() + pop + + ret + } + + // POSITIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class B`1>::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class B`1>::.ctor() + pop + + ret + } +} + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_ClassConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_ClassConstraint_Pos.ilproj new file mode 100644 index 0000000000..7be25616a1 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_ClassConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Instantiation_ClassConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_Constraints_Pos.cs b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_Constraints_Pos.cs new file mode 100644 index 0000000000..58db02e46d --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_Constraints_Pos.cs @@ -0,0 +1,151 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/* Test various combinations of constraints with legal parameter types by instantiating the types + +CONSTRAINTS: + +default ctor +reference type +valuetype +default ctor, reference type +default ctor, valuetype + +Test each constraint with (whatever applies for positive testing) +- Class with default nullary ctor (Generic/Non generic) +- Class with no default nullary ctor (Generic/Non generic) +- Class from mscorlib with default nullary ctor +- Abstract Class from mscorlib with no default nullary ctor + +- Struct from mscorlib (Generic/Non generic) +- Struct (Generic/Non generic) +- Enum (Generic/Non generic) + +- Interface (Generic/Non generic) + +- Array + +- Delegate + +- Nullable + + + +*/ + +using System; + + +public class Test +{ + static bool pass; + static int testNumber = 1; + + delegate void Case(); + + static void Check(Case mytest, string testName) + { + + Console.Write("Test"+testNumber + ": " + testName); + ++testNumber; + + + try + { + mytest(); + + + Console.WriteLine(" : PASS"); + return; + } + catch (TypeLoadException e) + { + Console.WriteLine("\nFAIL: Caught unexpected TypeLoadException: " + e); + pass = false; + return; + } + + catch (Exception e) + { + Console.WriteLine("\nFAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + + public static int Main() + { + pass = true; + + Console.WriteLine("\nType: A where T : new()\n"); + + Console.WriteLine("POSITIVE TESTS"); + Check(new Case(DefaultCtorConstraint.Test1), "Generic argument is a class with default ctor"); + Check(new Case(DefaultCtorConstraint.Test3), "Generic argument is a struct (valuetypes have public nullary ctors by default)"); + Check(new Case(DefaultCtorConstraint.Test5), "Generic argument is an mscorlib class with default ctor"); + Check(new Case(DefaultCtorConstraint.Test8), "Generic argument is an enum"); + Check(new Case(DefaultCtorConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor"); + Check(new Case(DefaultCtorConstraintGenTypes.Test3), "Generic argument is a generic struct"); + Check(new Case(DefaultCtorConstraintGenTypes.Test6), "Generic argument is Nullable"); + + + Console.WriteLine("\nType: A where T : class()\n"); + + Console.WriteLine("POSITIVE TESTS"); + Check(new Case(ClassConstraint.Test1), "Generic argument is a class with default ctor"); + Check(new Case(ClassConstraint.Test2), "Generic argument is a class with no default ctor"); + Check(new Case(ClassConstraint.Test4), "Generic argument is a delegate"); + Check(new Case(ClassConstraint.Test5), "Generic argument is an mscorlib class with default ctor"); + Check(new Case(ClassConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor"); + Check(new Case(ClassConstraint.Test7), "Generic argument is an interface"); + Check(new Case(ClassConstraint.Test9), "Generic argument is an array of classes with default ctor"); + Check(new Case(ClassConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor"); + Check(new Case(ClassConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor"); + Check(new Case(ClassConstraintGenTypes.Test5), "Generic argument is a generic interface"); + + + Console.WriteLine("\nType: A where T : struct()\n"); + + Console.WriteLine("POSITIVE TESTS"); + Check(new Case(StructConstraint.Test3), "Generic argument is a struct"); + Check(new Case(StructConstraint.Test8), "Generic argument is an enum"); + Check(new Case(StructConstraint.Test9), "Generic argument is an mscorlib struct"); + Check(new Case(StructConstraintGenTypes.Test3), "Generic argument is a generic struct"); + Check(new Case(StructConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct"); + + + + Console.WriteLine("\nType: A where T : class(), new() \n"); + + Console.WriteLine("POSITIVE TESTS"); + Check(new Case(DefaultCtorAndClassConstraint.Test1), "Generic argument is a class with default ctor"); + Check(new Case(DefaultCtorAndClassConstraint.Test5), "Generic argument is a is an mscorlib class with default ctor"); + Check(new Case(DefaultCtorAndClassConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor"); + + + Console.WriteLine("\nType: A where T : struct(), new()\n"); + + Console.WriteLine("POSITIVE TESTS"); + Check(new Case(DefaultCtorAndStructConstraint.Test3), "Generic argument is a struct"); + Check(new Case(DefaultCtorAndStructConstraint.Test9), "Generic argument is an mscorlib struct"); + Check(new Case(DefaultCtorAndStructConstraintGenTypes.Test3), "Generic argument is a generic struct"); + Check(new Case(DefaultCtorAndStructConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct"); + Check(new Case(DefaultCtorAndStructConstraint.Test8), "Generic argument is an enum"); + + + if (pass) + { + Console.WriteLine("PASS"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + } +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_Constraints_Pos.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_Constraints_Pos.csproj new file mode 100644 index 0000000000..f11d4b5a2c --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_Constraints_Pos.csproj @@ -0,0 +1,48 @@ + + + + + Instantiation_Constraints_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassConstraint_Pos.il new file mode 100644 index 0000000000..e24a554821 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassConstraint_Pos.il @@ -0,0 +1,80 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Instantiation_DefaultCtorAndClassConstraint_Pos {} + + +// Generic class with class() and new() constraints +.class public auto ansi beforefieldinit D`1 + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + + + +} + +.class public auto ansi beforefieldinit DefaultCtorAndClassConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + +} + +.class public auto ansi beforefieldinit DefaultCtorAndClassConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class D`1>::.ctor() + pop + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassConstraint_Pos.ilproj new file mode 100644 index 0000000000..f6c7873c97 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Instantiation_DefaultCtorAndClassConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassTypeConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassTypeConstraint_Pos.il new file mode 100644 index 0000000000..e92f92b8a0 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassTypeConstraint_Pos.il @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types_implementI_extendC{} + +.assembly Instantiation_DefaultCtorAndClassTypeConstraint_Pos {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit F`1<.ctor ([types_implementI_extendC]C) T> + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit Instantiation_DefaultCtorAndClassTypeConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor that implements I and extends C + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + + + + // POSITIVE TEST + // generic argument is a generic class with default ctor that implements I and extends C + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is a class with default ctor that doesn't implements I but extends C + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassTypeConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassTypeConstraint_Pos.ilproj new file mode 100644 index 0000000000..e6c72e025a --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndClassTypeConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Instantiation_DefaultCtorAndClassTypeConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndStructConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndStructConstraint_Pos.il new file mode 100644 index 0000000000..977aec5d90 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndStructConstraint_Pos.il @@ -0,0 +1,104 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Instantiation_DefaultCtorAndStructConstraint_Pos {} + + +// Generic class with struct() and new() constraints +.class public auto ansi beforefieldinit E`1 + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit DefaultCtorAndStructConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an enum + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib struct + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + +} + +.class public auto ansi beforefieldinit DefaultCtorAndStructConstraintGenTypes + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class E`1>::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib generic struct + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class E`1>::.ctor() + pop + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndStructConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndStructConstraint_Pos.ilproj new file mode 100644 index 0000000000..ffe14ae58d --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorAndStructConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Instantiation_DefaultCtorAndStructConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorConstraint_Pos.il new file mode 100644 index 0000000000..307938528d --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorConstraint_Pos.il @@ -0,0 +1,144 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Instantiation_DefaultCtorConstraint_Pos {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit A`1<.ctor T> + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit DefaultCtorConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is a struct (valuetypes have public nullary ctors by default) + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an enum with no default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + + // generic argument is NUllable + .method public hidebysig static void Test10() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + +} + +.class public auto ansi beforefieldinit DefaultCtorConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class A`1>::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class A`1>::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class A`1>::.ctor() + pop + + ret + } + + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorConstraint_Pos.ilproj new file mode 100644 index 0000000000..281b435fef --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_DefaultCtorConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Instantiation_DefaultCtorConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_StructConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_StructConstraint_Pos.il new file mode 100644 index 0000000000..bf7a82c3a1 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_StructConstraint_Pos.il @@ -0,0 +1,104 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly Instantiation_StructConstraint_Pos {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit C`1 + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit StructConstraint + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class C`1::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an enum + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + newobj instance void class C`1::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib struct + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + newobj instance void class C`1::.ctor() + pop + + ret + } + +} + +.class public auto ansi beforefieldinit StructConstraintGenTypes + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class C`1>::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib generic struct + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + newobj instance void class C`1>::.ctor() + pop + + ret + } +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_StructConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_StructConstraint_Pos.ilproj new file mode 100644 index 0000000000..6508369179 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Instantiation_StructConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Instantiation_StructConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassConstraint_Pos.il new file mode 100644 index 0000000000..0214f0ac72 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassConstraint_Pos.il @@ -0,0 +1,68 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types_implementI{} + +.assembly Interface_DefaultCtorAndClassConstraint_Pos {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit D`1 + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit Interface_DefaultCtorAndClassConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class D`1::.ctor() + pop + + ret + } + + + + + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class D`1>::.ctor() + pop + + ret + } + + + + + + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassConstraint_Pos.ilproj new file mode 100644 index 0000000000..f6541b415d --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Interface_DefaultCtorAndClassConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassTypeConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassTypeConstraint_Pos.il new file mode 100644 index 0000000000..73b4341d1d --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassTypeConstraint_Pos.il @@ -0,0 +1,68 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types_implementI_extendC{} + +.assembly Interface_DefaultCtorAndClassTypeConstraint_Pos {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit F`1<.ctor ([types_implementI_extendC]C, [types_implementI_extendC]I) T> + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit Interface_DefaultCtorAndClassTypeConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor that implements I and extends C + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class F`1::.ctor() + pop + + ret + } + + + + + // POSITIVE TEST + // generic argument is a generic class with default ctor that implements I and extends C + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class F`1>::.ctor() + pop + + ret + } + + + + + + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassTypeConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassTypeConstraint_Pos.ilproj new file mode 100644 index 0000000000..3aa0fd70af --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndClassTypeConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Interface_DefaultCtorAndClassTypeConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndStructConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndStructConstraint_Pos.il new file mode 100644 index 0000000000..e3d332530f --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndStructConstraint_Pos.il @@ -0,0 +1,66 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types_implementI{} + +.assembly Interface_DefaultCtorAndStructConstraint_Pos {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit E`1 + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit Interface_DefaultCtorAndStructConstraint + extends [mscorlib]System.Object +{ + // NEGATIVE TEST + // generic argument is a struct (valuetypes have public nullary ctors by default) + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class E`1::.ctor() + pop + + ret + } + + + // NEGATIVE TEST + // generic argument is a struct + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class E`1>::.ctor() + pop + + ret + } + + + + + + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndStructConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndStructConstraint_Pos.ilproj new file mode 100644 index 0000000000..d3bebb3289 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorAndStructConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Interface_DefaultCtorAndStructConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorConstraint_Pos.il new file mode 100644 index 0000000000..f6b7d148fe --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorConstraint_Pos.il @@ -0,0 +1,86 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types_implementI{} + +.assembly Interface_DefaultCtorConstraint_Pos {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit A`1<.ctor ([types_implementI]I) T> + extends [mscorlib]System.Object +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit Interface_DefaultCtorConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + + + // POSITIVE TEST + // generic argument is a struct (valuetypes have public nullary ctors by default) + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + newobj instance void class A`1::.ctor() + pop + + ret + } + + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + newobj instance void class A`1>::.ctor() + pop + + ret + } + + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + newobj instance void class A`1>::.ctor() + pop + + ret + } + +} + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorConstraint_Pos.ilproj new file mode 100644 index 0000000000..4722c83401 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/Interface_DefaultCtorConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + Interface_DefaultCtorConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos.il new file mode 100644 index 0000000000..58f9377162 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos.il @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } +// this file contains positive tests for +// G where T : U where U : struct +// C# didn't want to compile such type definition so we are using IL. + + +.assembly extern mscorlib {} +.assembly extern TypeParam_Constraints_Pos {} +.assembly RunTestPos {} + + +.class public auto ansi beforefieldinit GStruct`2<(!U) T, valuetype U> + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + + +.class public auto ansi beforefieldinit RunGStructTest + extends [mscorlib]System.Object +{ + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + newobj instance void class GStruct`2::.ctor() + pop + ret + } + + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + newobj instance void class GStruct`2::.ctor() + pop + ret + } +} + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos.ilproj new file mode 100644 index 0000000000..09852112b4 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos.ilproj @@ -0,0 +1,42 @@ + + + + + RunTestPos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos2.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos2.il new file mode 100644 index 0000000000..d0ff480f36 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos2.il @@ -0,0 +1,57 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } +// this file contains positive test for +// GStruct where T : struct +// G4

: GStruct

where P : valuetype S + +// C# didn't want to compile such type definition so we are using IL. + + +.assembly extern mscorlib {} +.assembly extern TypeParam2_Constraints_Pos {} +.assembly RunTestPos2 {} + +.class public auto ansi beforefieldinit GStruct`1 + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit G4`1<(valuetype [TypeParam2_Constraints_Pos]S) P> + extends class GStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + + +.class public sequential ansi sealed beforefieldinit S_PrivCtor + extends [mscorlib]System.ValueType +{ + .pack 0 + .size 1 +} + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos2.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos2.ilproj new file mode 100644 index 0000000000..54739ed81b --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos2.ilproj @@ -0,0 +1,42 @@ + + + + + RunTestPos2 + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos3.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos3.il new file mode 100644 index 0000000000..45afb6d897 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos3.il @@ -0,0 +1,57 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } +// this file contains positive test for +// interface IStruct where T : struct +// G4

: IStruct

where P : valuetype S + +// C# didn't want to compile such type definition so we are using IL. + + +.assembly extern mscorlib {} +.assembly extern TypeParam3_Constraints_Pos {} +.assembly RunTestPos3 {} + +.class interface public abstract auto ansi IStruct`1 {} + + +.class public auto ansi beforefieldinit G4`1<(valuetype [TypeParam3_Constraints_Pos]S) P> + implements class IStruct`1 +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + + +.class public sequential ansi sealed beforefieldinit S_PrivCtor + extends [mscorlib]System.ValueType +{ + .pack 0 + .size 1 + + .method private hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos3.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos3.ilproj new file mode 100644 index 0000000000..41469c2098 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/RunTestPos3.ilproj @@ -0,0 +1,42 @@ + + + + + RunTestPos3 + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_ClassConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_ClassConstraint_Pos.il new file mode 100644 index 0000000000..8e39680aed --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_ClassConstraint_Pos.il @@ -0,0 +1,173 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticField_ClassConstraint_Pos {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit B`1 + extends [mscorlib]System.Object +{ + + .field public static int32 i + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SF_ClassConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1::i + pop + + ret + } + + // POSITIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is a delegate + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1::i + pop + + ret + } + + + + // POSITIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + ldsfld int32 class B`1::i + pop + ret + } + + + // POSITIVE TEST + // generic argument is an interface + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + ldsfld int32 class B`1::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1::i + pop + + ret + } + + + +} + +.class public auto ansi beforefieldinit SF_ClassConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1>::i + pop + + ret + } + + // POSITIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1>::i + pop + + ret + } + + + + // POSITIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + ldsfld int32 class B`1>::i + pop + + ret + } + +} + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_ClassConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_ClassConstraint_Pos.ilproj new file mode 100644 index 0000000000..864e7cbd71 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_ClassConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + StaticField_ClassConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_Constraints_Pos.cs b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_Constraints_Pos.cs new file mode 100644 index 0000000000..70715d8e44 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_Constraints_Pos.cs @@ -0,0 +1,157 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/* Test various combinations of constraints with legal parameter types accessing static field of the generic type + +CONSTRAINTS: + +default ctor +reference type +valuetype +default ctor, reference tyoe +default ctor, valuetype + +Test each constraint with (whichever apply for positive tests) +- Class with default nullary ctor (Generic/Non generic) +- Class with no default nullary ctor (Generic/Non generic) +- Class from mscorlib with default nullary ctor +- Abstract Class from mscorlib with no default nullary ctor + +- Struct from mscorlib (Generic/Non generic) +- Struct (Generic/Non generic) +- Enum (Generic/Non generic) + +- Interface (Generic/Non generic) + +- Array + +- Delegate + +- Nullable + +*/ + +using System; + + +public class Test +{ + static bool pass; + static int testNumber = 1; + + delegate void Case(); + + + static void Check(Case mytest, string testName) + { + + Console.Write("Test"+testNumber + ": " + testName); + ++testNumber; + + + try + { + mytest(); + + + Console.WriteLine(" : PASS"); + return; + } + catch (TypeLoadException e) + { + Console.WriteLine("\nFAIL: Caught unexpected TypeLoadException: " + e); + pass = false; + return; + } + + catch (Exception e) + { + Console.WriteLine("\nFAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + + + public static int Main() + { + pass = true; + + Console.WriteLine("\nType: A where T : new()\n"); + Console.WriteLine("POSITIVE TESTS"); + + Check(new Case(SF_DefaultCtorConstraint.Test1), "Generic argument is a class with default ctor"); + Check(new Case(SF_DefaultCtorConstraint.Test3), "Generic argument is a struct (valuetypes have public nullary ctors by default)"); + Check(new Case(SF_DefaultCtorConstraint.Test5), "Generic argument is an mscorlib class with default ctor"); + // enum is a valueypte and all valuetypes have public nullary ctors. + Check(new Case(SF_DefaultCtorConstraint.Test8), "Generic argument is an enum"); + Check(new Case(SF_DefaultCtorConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor"); + Check(new Case(SF_DefaultCtorConstraintGenTypes.Test3), "Generic argument is a generic struct"); + Check(new Case(SF_DefaultCtorConstraintGenTypes.Test6), "Generic argument is Nullable"); + + + Console.WriteLine("\nType: A where T : class()\n"); + Console.WriteLine("POSITIVE TESTS"); + + Check(new Case(SF_ClassConstraint.Test1), "Generic argument is a class with default ctor"); + Check(new Case(SF_ClassConstraint.Test2), "Generic argument is a class with no default ctor"); + Check(new Case(SF_ClassConstraint.Test4), "Generic argument is a delegate"); + Check(new Case(SF_ClassConstraint.Test5), "Generic argument is an mscorlib class with default ctor"); + Check(new Case(SF_ClassConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor"); + Check(new Case(SF_ClassConstraint.Test7), "Generic argument is an interface"); + Check(new Case(SF_ClassConstraint.Test9), "Generic argument is an array of classes with default ctor"); + Check(new Case(SF_ClassConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor"); + Check(new Case(SF_ClassConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor"); + Check(new Case(SF_ClassConstraintGenTypes.Test5), "Generic argument is a generic interface"); + + + + Console.WriteLine("\nType: A where T : struct()\n"); + Console.WriteLine("POSITIVE TESTS"); + + Check(new Case(SF_StructConstraint.Test3), "Generic argument is a struct"); + Check(new Case(SF_StructConstraint.Test8), "Generic argument is an enum"); + Check(new Case(SF_StructConstraint.Test9), "Generic argument is an mscorlib struct"); + Check(new Case(SF_StructConstraintGenTypes.Test3), "Generic argument is a generic struct"); + Check(new Case(SF_StructConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct"); + + + + Console.WriteLine("\nType: A where T : class(), new() \n"); + Console.WriteLine("POSITIVE TESTS"); + + Check(new Case(SF_DefaultCtorAndClassConstraint.Test1), "Generic argument is a class with default ctor"); + Check(new Case(SF_DefaultCtorAndClassConstraint.Test5), "Generic argument is a is an mscorlib class with default ctor"); + Check(new Case(SF_DefaultCtorAndClassConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor"); + + + + Console.WriteLine("\nType: A where T : struct(), new()\n"); + Console.WriteLine("POSITIVE TESTS"); + + + Check(new Case(SF_DefaultCtorAndStructConstraint.Test3), "Generic argument is a struct"); + Check(new Case(SF_DefaultCtorAndStructConstraint.Test9), "Generic argument is an mscorlib struct"); + Check(new Case(SF_DefaultCtorAndStructConstraintGenTypes.Test3), "Generic argument is a generic struct"); + Check(new Case(SF_DefaultCtorAndStructConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct"); + Check(new Case(SF_DefaultCtorAndStructConstraint.Test8), "Generic argument is an enum"); + + + + + if (pass) + { + Console.WriteLine("PASS"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + } +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_Constraints_Pos.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_Constraints_Pos.csproj new file mode 100644 index 0000000000..f46552f33e --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_Constraints_Pos.csproj @@ -0,0 +1,48 @@ + + + + + StaticField_Constraints_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndClassConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndClassConstraint_Pos.il new file mode 100644 index 0000000000..078ac97f8c --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndClassConstraint_Pos.il @@ -0,0 +1,83 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticField_DefaultCtorAndClassConstraint_Pos {} + + +// Generic class with class() and new() constraints +.class public auto ansi beforefieldinit D`1 + extends [mscorlib]System.Object +{ + + .field public static int32 i + + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + + + +} + +.class public auto ansi beforefieldinit SF_DefaultCtorAndClassConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1::i + pop + + ret + } + + +} + +.class public auto ansi beforefieldinit SF_DefaultCtorAndClassConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + ldsfld int32 class D`1>::i + pop + + ret + } +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndClassConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndClassConstraint_Pos.ilproj new file mode 100644 index 0000000000..13b68b394b --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndClassConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + StaticField_DefaultCtorAndClassConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndStructConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndStructConstraint_Pos.il new file mode 100644 index 0000000000..6a649cb0b4 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndStructConstraint_Pos.il @@ -0,0 +1,112 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticField_DefaultCtorAndStructConstraint_Pos {} + + +// Generic class with struct() and new() constraints +.class public auto ansi beforefieldinit E`1 + extends [mscorlib]System.Object +{ + + .field public static int32 i + + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SF_DefaultCtorAndStructConstraint + extends [mscorlib]System.Object +{ + + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an enum + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib struct + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1::i + pop + + ret + } + +} + +.class public auto ansi beforefieldinit SF_DefaultCtorAndStructConstraintGenTypes + extends [mscorlib]System.Object +{ + + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1>::i + pop + + ret + } + + + + // POSITIVE TEST + // generic argument is an mscorlib generic struct + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + ldsfld int32 class E`1>::i + pop + + ret + } + + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndStructConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndStructConstraint_Pos.ilproj new file mode 100644 index 0000000000..435347ac94 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorAndStructConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + StaticField_DefaultCtorAndStructConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorConstraint_Pos.il new file mode 100644 index 0000000000..8c76992797 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorConstraint_Pos.il @@ -0,0 +1,133 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticField_DefaultCtorConstraint_Pos {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit A`1<.ctor T> + extends [mscorlib]System.Object +{ + + .field public static int32 i + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit SF_DefaultCtorConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is a struct (valuetypes have public nullary ctors by default) + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1::i + pop + + ret + } + + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an enum with no default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1::i + pop + + ret + } + +} + +.class public auto ansi beforefieldinit SF_DefaultCtorConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1>::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1>::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + ldsfld int32 class A`1>::i + pop + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorConstraint_Pos.ilproj new file mode 100644 index 0000000000..8d4711e466 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_DefaultCtorConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + StaticField_DefaultCtorConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_StructConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_StructConstraint_Pos.il new file mode 100644 index 0000000000..b1ab85a5f5 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_StructConstraint_Pos.il @@ -0,0 +1,108 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticField_StructConstraint_Pos {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit C`1 + extends [mscorlib]System.Object +{ + .field public static int32 i + + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SF_StructConstraint + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an enum + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib struct + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1::i + pop + + ret + } + +} + +.class public auto ansi beforefieldinit SF_StructConstraintGenTypes + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1>::i + pop + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib generic struct + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + ldsfld int32 class C`1>::i + + pop + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_StructConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_StructConstraint_Pos.ilproj new file mode 100644 index 0000000000..5d9d2fad9a --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticField_StructConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + StaticField_StructConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_ClassConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_ClassConstraint_Pos.il new file mode 100644 index 0000000000..381742b589 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_ClassConstraint_Pos.il @@ -0,0 +1,154 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticMethod_ClassConstraint_Pos {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit B`1 + extends [mscorlib]System.Object +{ + + .method public static hidebysig void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SM_ClassConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + call void class B`1::method1() + ret + } + + // POSITIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + call void class B`1::method1() + ret + } + + + // POSITIVE TEST + // generic argument is a delegate + .method public hidebysig static void Test4() cil managed + { + .maxstack 1 + + call void class B`1::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + call void class B`1::method1() + ret + } + + + + // POSITIVE TEST + // generic argument is an mscorlib abstract class with no default ctor + + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + + call void class B`1::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an interface + .method public hidebysig static void Test7() cil managed + { + .maxstack 1 + call void class B`1::method1() + ret + } + + // POSITIVE TEST + // generic argument is an array of classes with default ctor + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + call void class B`1::method1() + ret + } + + + +} + +.class public auto ansi beforefieldinit SM_ClassConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + call void class B`1>::method1() + ret + } + + // POSITIVE TEST + // generic argument is a class with no default ctor + .method public hidebysig static void Test2() cil managed + { + .maxstack 1 + + call void class B`1>::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an interface with no default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + call void class B`1>::method1() + ret + } + +} + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_ClassConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_ClassConstraint_Pos.ilproj new file mode 100644 index 0000000000..53f0e0c729 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_ClassConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + StaticMethod_ClassConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_Constraints_Pos.cs b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_Constraints_Pos.cs new file mode 100644 index 0000000000..869759b590 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_Constraints_Pos.cs @@ -0,0 +1,152 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/* Test various combinations of constraints with legal parameter types by invoking static method on the generic type +CONSTRAINTS: + +default ctor +reference type +valuetype +default ctor, reference tyoe +default ctor, valuetype + +Test each constraint with (whichever apply to positive tests) +- Class with default nullary ctor (Generic/Non generic) +- Class with no default nullary ctor (Generic/Non generic) +- Class from mscorlib with default nullary ctor +- Abstract Class from mscorlib with no default nullary ctor + +- Struct from mscorlib (Generic/Non generic) +- Struct (Generic/Non generic) +- Enum (Generic/Non generic) + +- Interface (Generic/Non generic) + +- Array + +- Delegate + +- Nullable +*/ + +using System; + + +public class Test +{ + static bool pass; + static int testNumber = 1; + + delegate void Case(); + + + + static void Check(Case mytest, string testName) + { + + Console.Write("Test"+testNumber + ": " + testName); + ++testNumber; + + + try + { + mytest(); + + + Console.WriteLine(" : PASS"); + return; + } + catch (TypeLoadException e) + { + Console.WriteLine("\nFAIL: Caught unexpected TypeLoadException: " + e); + pass = false; + return; + } + + catch (Exception e) + { + Console.WriteLine("\nFAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + + + public static int Main() + { + pass = true; + + Console.WriteLine("\nType: A where T : new()\n"); + Console.WriteLine("POSITIVE TESTS"); + + Check(new Case(SM_DefaultCtorConstraint.Test1), "Generic argument is a class with default ctor" ); + Check(new Case(SM_DefaultCtorConstraint.Test3), "Generic argument is a struct (valuetypes have public nullary ctors by default)"); + Check(new Case(SM_DefaultCtorConstraint.Test5), "Generic argument is an mscorlib class with default ctor"); + // enum is a valueypte and all valuetypes have public nullary ctors. + Check(new Case(SM_DefaultCtorConstraint.Test8), "Generic argument is an enum"); + Check(new Case(SM_DefaultCtorConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor"); + Check(new Case(SM_DefaultCtorConstraintGenTypes.Test3), "Generic argument is a generic struct"); + Check(new Case(SM_DefaultCtorConstraintGenTypes.Test6), "Generic argument is Nullable"); + + + Console.WriteLine("\nType: A where T : class()\n"); + Console.WriteLine("POSITIVE TESTS"); + + Check(new Case(SM_ClassConstraint.Test1), "Generic argument is a class with default ctor"); + Check(new Case(SM_ClassConstraint.Test2), "Generic argument is a class with no default ctor"); + Check(new Case(SM_ClassConstraint.Test4), "Generic argument is a delegate"); + Check(new Case(SM_ClassConstraint.Test5), "Generic argument is an mscorlib class with default ctor"); + Check(new Case(SM_ClassConstraint.Test6), "Generic argument is an mscorlib abstract class with no default ctor"); + Check(new Case(SM_ClassConstraint.Test7), "Generic argument is an interface"); + Check(new Case(SM_ClassConstraint.Test9), "Generic argument is an array of classes with default ctor"); + Check(new Case(SM_ClassConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor"); + Check(new Case(SM_ClassConstraintGenTypes.Test2), "Generic argument is a generic class with no default ctor"); + Check(new Case(SM_ClassConstraintGenTypes.Test5), "Generic argument is a generic interface"); + + + Console.WriteLine("\nType: A where T : struct()\n"); + Console.WriteLine("POSITIVE TESTS"); + + Check(new Case(SM_StructConstraint.Test3), "Generic argument is a struct"); + Check(new Case(SM_StructConstraint.Test8), "Generic argument is an enum"); + Check(new Case(SM_StructConstraint.Test9), "Generic argument is an mscorlib struct"); + Check(new Case(SM_StructConstraintGenTypes.Test3), "Generic argument is a generic struct"); + Check(new Case(SM_StructConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct"); + + + + Console.WriteLine("\nType: A where T : class(), new() \n"); + Console.WriteLine("POSITIVE TESTS"); + + Check(new Case(SM_DefaultCtorAndClassConstraint.Test1), "Generic argument is a class with default ctor"); + Check(new Case(SM_DefaultCtorAndClassConstraint.Test5), "Generic argument is a is an mscorlib class with default ctor"); + Check(new Case(SM_DefaultCtorAndClassConstraintGenTypes.Test1), "Generic argument is a generic class with default ctor"); + + + + Console.WriteLine("\nType: A where T : struct(), new()\n"); + Console.WriteLine("POSITIVE TESTS"); + + Check(new Case(SM_DefaultCtorAndStructConstraint.Test3), "Generic argument is a struct"); + Check(new Case(SM_DefaultCtorAndStructConstraint.Test9), "Generic argument is an mscorlib struct"); + Check(new Case(SM_DefaultCtorAndStructConstraintGenTypes.Test3), "Generic argument is a generic struct"); + Check(new Case(SM_DefaultCtorAndStructConstraintGenTypes.Test6), "Generic argument is a generic mscorlib struct"); + Check(new Case(SM_DefaultCtorAndStructConstraint.Test8), "Generic argument is an enum"); + + + if (pass) + { + Console.WriteLine("PASS"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + } +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_Constraints_Pos.csproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_Constraints_Pos.csproj new file mode 100644 index 0000000000..fa0690db03 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_Constraints_Pos.csproj @@ -0,0 +1,48 @@ + + + + + StaticMethod_Constraints_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndClassConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndClassConstraint_Pos.il new file mode 100644 index 0000000000..11458e132e --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndClassConstraint_Pos.il @@ -0,0 +1,79 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticMethod_DefaultCtorAndClassConstraint_Pos {} + + +// Generic class with class() and new() constraints +.class public auto ansi beforefieldinit D`1 + extends [mscorlib]System.Object +{ + + .method public static hidebysig void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + + + +} + +.class public auto ansi beforefieldinit SM_DefaultCtorAndClassConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + call void class D`1::method1() + ret + } + + + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + + call void class D`1::method1() + ret + } + +} + +.class public auto ansi beforefieldinit SM_DefaultCtorAndClassConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + call void class D`1>::method1() + ret + } + +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndClassConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndClassConstraint_Pos.ilproj new file mode 100644 index 0000000000..91d0d6d1c9 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndClassConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + StaticMethod_DefaultCtorAndClassConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndStructConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndStructConstraint_Pos.il new file mode 100644 index 0000000000..461387c9c9 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndStructConstraint_Pos.il @@ -0,0 +1,102 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticMethod_DefaultCtorAndStructConstraint_Pos {} + + +// Generic class with struct() and new() constraints +.class public auto ansi beforefieldinit E`1 + extends [mscorlib]System.Object +{ + + .method public static hidebysig void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SM_DefaultCtorAndStructConstraint + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + call void class E`1::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an enum + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + call void class E`1::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib struct + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + call void class E`1::method1() + ret + } + +} + +.class public auto ansi beforefieldinit SM_DefaultCtorAndStructConstraintGenTypes + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + call void class E`1>::method1() + ret + } + + // POSITIVE TEST + // generic argument is an mscorlib generic struct + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + call void class E`1>::method1() + + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndStructConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndStructConstraint_Pos.ilproj new file mode 100644 index 0000000000..1f17e790fc --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorAndStructConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + StaticMethod_DefaultCtorAndStructConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorConstraint_Pos.il new file mode 100644 index 0000000000..4ebbba6d47 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorConstraint_Pos.il @@ -0,0 +1,124 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticMethod_DefaultCtorConstraint_Pos {} + + +// Generic class with new() constraint +.class public auto ansi beforefieldinit A`1<.ctor T> + extends [mscorlib]System.Object +{ + + .method public static hidebysig void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } + +} + +.class public auto ansi beforefieldinit SM_DefaultCtorConstraint + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + call void class A`1::method1() + + ret + } + + + // POSITIVE TEST + // generic argument is a struct (valuetypes have public nullary ctors by default) + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + call void class A`1::method1() + + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib class with default ctor + .method public hidebysig static void Test5() cil managed + { + .maxstack 1 + call void class A`1::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an enum with no default ctor + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + call void class A`1::method1() + ret + } + +} + +.class public auto ansi beforefieldinit SM_DefaultCtorConstraintGenTypes + extends [mscorlib]System.Object +{ + // POSITIVE TEST + // generic argument is a class with default ctor + .method public hidebysig static void Test1() cil managed + { + .maxstack 1 + + call void class A`1>::method1() + ret + } + + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + call void class A`1>::method1() + ret + } + + + // POSITIVE TEST + // generic argument is NUllable + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + call void class A`1>::method1() + ret + } + +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorConstraint_Pos.ilproj new file mode 100644 index 0000000000..8d62ad1d96 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_DefaultCtorConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + StaticMethod_DefaultCtorConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_StructConstraint_Pos.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_StructConstraint_Pos.il new file mode 100644 index 0000000000..ff434d1ef9 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_StructConstraint_Pos.il @@ -0,0 +1,101 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} +.assembly extern types{} + +.assembly StaticMethod_StructConstraint_Pos {} + + +// Generic class with class() constraint +.class public auto ansi beforefieldinit C`1 + extends [mscorlib]System.Object +{ + + .method public static hidebysig void + method1() cil managed + { + .maxstack 8 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +.class public auto ansi beforefieldinit SM_StructConstraint + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + call void class C`1::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an enum + .method public hidebysig static void Test8() cil managed + { + .maxstack 1 + + call void class C`1::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib struct + .method public hidebysig static void Test9() cil managed + { + .maxstack 1 + + call void class C`1::method1() + ret + } +} + +.class public auto ansi beforefieldinit SM_StructConstraintGenTypes + extends [mscorlib]System.Object +{ + + // POSITIVE TEST + // generic argument is a struct + .method public hidebysig static void Test3() cil managed + { + .maxstack 1 + + call void class C`1>::method1() + ret + } + + + // POSITIVE TEST + // generic argument is an mscorlib generic struct + .method public hidebysig static void Test6() cil managed + { + .maxstack 1 + + call void class C`1>::method1() + + ret + } +} + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_StructConstraint_Pos.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_StructConstraint_Pos.ilproj new file mode 100644 index 0000000000..4698beeb5e --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/StaticMethod_StructConstraint_Pos.ilproj @@ -0,0 +1,38 @@ + + + + + StaticMethod_StructConstraint_Pos + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/app.config b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/app.config new file mode 100644 index 0000000000..e5622f77ad --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/project.json b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/project.json new file mode 100644 index 0000000000..a2e84dc340 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types.il new file mode 100644 index 0000000000..53c0b9e255 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types.il @@ -0,0 +1,117 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} + +.assembly Types {} + +// class with public nullary ctor +.class public auto ansi beforefieldinit ClassWithCtor + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +// generic class with public nullary ctor +.class public auto ansi beforefieldinit GenClassWithCtor + extends [mscorlib]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +// class without public nullary ctor +.class public auto ansi beforefieldinit ClassNoCtor + extends [mscorlib]System.Object +{ +} + +// generic class without public nullary ctor +.class public auto ansi beforefieldinit GenClassNoCtor + extends [mscorlib]System.Object +{ +} + + +// struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit NonGenStruct + extends [mscorlib]System.ValueType +{ + .pack 0 + .size 1 +} + + + +// generic struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit GenStruct + extends [mscorlib]System.ValueType +{ + .pack 0 + .size 1 +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit NonGenInterface +{ +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit GenInterface +{ +} + + +.class public auto ansi sealed Enum1 + extends [mscorlib]System.Enum +{ + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype Enum1 One = int32(0x00000000) +} + + +// doesn't have public parameterless constructor +.class public auto ansi sealed Delegate1 + extends [mscorlib]System.MulticastDelegate +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor(object 'object', + native int 'method') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void Invoke() runtime managed + { + } + + .method public hidebysig newslot virtual + instance class [mscorlib]System.IAsyncResult + BeginInvoke(class [mscorlib]System.AsyncCallback callback, + object 'object') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void EndInvoke(class [mscorlib]System.IAsyncResult result) runtime managed + { + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types.ilproj new file mode 100644 index 0000000000..e90ddd06ea --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types.ilproj @@ -0,0 +1,38 @@ + + + + + types + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI.il new file mode 100644 index 0000000000..56a463547c --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI.il @@ -0,0 +1,131 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} + +.assembly Types_implementI {} + + +.class interface public abstract auto ansi I {} + + +// class with public nullary ctor +.class public auto ansi beforefieldinit ClassWithCtor + extends [mscorlib]System.Object + implements I + +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +// generic class with public nullary ctor +.class public auto ansi beforefieldinit GenClassWithCtor + extends [mscorlib]System.Object + implements I +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +// class without public nullary ctor +.class public auto ansi beforefieldinit ClassNoCtor + extends [mscorlib]System.Object + implements I +{ +} + +// generic class without public nullary ctor +.class public auto ansi beforefieldinit GenClassNoCtor + extends [mscorlib]System.Object + implements I +{ +} + + +// struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit NonGenStruct + extends [mscorlib]System.ValueType + implements I +{ + .pack 0 + .size 1 +} + + + +// generic struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit GenStruct + extends [mscorlib]System.ValueType + implements I +{ + .pack 0 + .size 1 +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit NonGenInterface + implements I +{ +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit GenInterface + implements I +{ +} + + +.class public auto ansi sealed Enum1 + extends [mscorlib]System.Enum +{ + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype Enum1 One = int32(0x00000000) +} + + +// doesn't have public parameterless constructor +.class public auto ansi sealed Delegate1 + extends [mscorlib]System.MulticastDelegate + implements I +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor(object 'object', + native int 'method') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void Invoke() runtime managed + { + } + + .method public hidebysig newslot virtual + instance class [mscorlib]System.IAsyncResult + BeginInvoke(class [mscorlib]System.AsyncCallback callback, + object 'object') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void EndInvoke(class [mscorlib]System.IAsyncResult result) runtime managed + { + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI.ilproj new file mode 100644 index 0000000000..56d5b6ed3e --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI.ilproj @@ -0,0 +1,38 @@ + + + + + types_implementI + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI_extendC.il b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI_extendC.il new file mode 100644 index 0000000000..7bbe76e361 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI_extendC.il @@ -0,0 +1,151 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +.assembly extern System.Console { } + +.assembly extern mscorlib{} + +.assembly types_implementI_extendC {} + + +.class interface public abstract auto ansi I {} + +.class public auto ansi beforefieldinit C + extends [mscorlib]System.Object + implements I + +{} + +// class with public nullary ctor +.class public auto ansi beforefieldinit ClassWithCtor + extends C + implements I + +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +// class with public nullary ctor extends C but doesn't implement I +.class public auto ansi beforefieldinit ClassWithCtor2 + extends C + +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + +// generic class with public nullary ctor +.class public auto ansi beforefieldinit GenClassWithCtor + extends C + implements I +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + .maxstack 8 + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } +} + + +// class without public nullary ctor +.class public auto ansi beforefieldinit ClassNoCtor + extends C + implements I +{ +} + +// generic class without public nullary ctor +.class public auto ansi beforefieldinit GenClassNoCtor + extends C + implements I +{ +} + + +// struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit NonGenStruct + extends [mscorlib]System.ValueType + implements I +{ + .pack 0 + .size 1 +} + + + +// generic struct (valuetypes have public nullary ctors by default) +.class public sequential ansi sealed beforefieldinit GenStruct + extends [mscorlib]System.ValueType + implements I +{ + .pack 0 + .size 1 +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit NonGenInterface + implements I +{ +} + +// interface without public nullary ctor +.class public abstract interface auto ansi beforefieldinit GenInterface + implements I +{ +} + + +.class public auto ansi sealed Enum1 + extends [mscorlib]System.Enum +{ + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype Enum1 One = int32(0x00000000) +} + + +// doesn't have public parameterless constructor +.class public auto ansi sealed Delegate1 + extends [mscorlib]System.MulticastDelegate + implements I +{ + + .method public hidebysig specialname rtspecialname + instance void .ctor(object 'object', + native int 'method') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void Invoke() runtime managed + { + } + + .method public hidebysig newslot virtual + instance class [mscorlib]System.IAsyncResult + BeginInvoke(class [mscorlib]System.AsyncCallback callback, + object 'object') runtime managed + { + } + + .method public hidebysig newslot virtual + instance void EndInvoke(class [mscorlib]System.IAsyncResult result) runtime managed + { + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI_extendC.ilproj b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI_extendC.ilproj new file mode 100644 index 0000000000..783be27964 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/ConstraintsOnType/Positive/types_implementI_extendC.ilproj @@ -0,0 +1,38 @@ + + + + + types_implementI_extendC + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + true + Library + BuildOnly + 0 + + + + + False + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/General/ManyGenConstraints.cs b/tests/src/Loader/classloader/generics/Constraints/General/ManyGenConstraints.cs new file mode 100644 index 0000000000..983cc508af --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/General/ManyGenConstraints.cs @@ -0,0 +1,155 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// this test has a generic type with 100 constraints +// we want to make sure we can load such type. + +using System; + +public class Test { + public static int Main() + { + bool pass = true; + + try + { + MyClass obj = new MyClass(); + } + catch (Exception e) + { + Console.WriteLine("Caught unexpected exception: " + e); + pass = false; + } + + try + { + // warning CS0219: The variable 'obj' is assigned but its value is never used + #pragma warning disable 219 + MyStruct obj = new MyStruct(); + #pragma warning restore 219 + } + catch (Exception e) + { + Console.WriteLine("Caught unexpected exception: " + e); + pass = false; + } + + + if (pass) + { + Console.WriteLine("PASS"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + } +} + +public class MyClass where T : I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, I17, I18, I19, I20, I21, I22, I23, I24, I25, I26, I27, I28, I29, I30, I31, I32, I33, I34, I35, I36, I37, I38, I39, I40, I41, I42, I43, I44, I45, I46, I47, I48, I49, I50, I51, I52, I53, I54, I55, I56, I57, I58, I59, I60, I61, I62, I63, I64, I65, I66, I67, I68, I69, I70, I71, I72, I73, I74, I75, I76, I77, I78, I79, I80, I81, I82, I83, I84, I85, I86, I87, I88, I89, I90, I91, I92, I93, I94, I95, I96, I97, I98, I99, I100{} + +public struct MyStruct where T : I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, I17, I18, I19, I20, I21, I22, I23, I24, I25, I26, I27, I28, I29, I30, I31, I32, I33, I34, I35, I36, I37, I38, I39, I40, I41, I42, I43, I44, I45, I46, I47, I48, I49, I50, I51, I52, I53, I54, I55, I56, I57, I58, I59, I60, I61, I62, I63, I64, I65, I66, I67, I68, I69, I70, I71, I72, I73, I74, I75, I76, I77, I78, I79, I80, I81, I82, I83, I84, I85, I86, I87, I88, I89, I90, I91, I92, I93, I94, I95, I96, I97, I98, I99, I100{} + +public interface I1 {} +public interface I2 : I1{} +public interface I3 : I2{} +public interface I4 : I3{} +public interface I5 : I4{} +public interface I6 : I5{} +public interface I7 : I6{} +public interface I8 : I7{} +public interface I9 : I8{} +public interface I10 : I9{} +public interface I11 : I10{} +public interface I12 : I11{} +public interface I13 : I12{} +public interface I14 : I13{} +public interface I15 : I14{} +public interface I16 : I15{} +public interface I17 : I16{} +public interface I18 : I17{} +public interface I19 : I18{} +public interface I20 : I19{} +public interface I21 : I20{} +public interface I22 : I21{} +public interface I23 : I22{} +public interface I24 : I23{} +public interface I25 : I24{} +public interface I26 : I25{} +public interface I27 : I26{} +public interface I28 : I27{} +public interface I29 : I28{} +public interface I30 : I29{} +public interface I31 : I30{} +public interface I32 : I31{} +public interface I33 : I32{} +public interface I34 : I33{} +public interface I35 : I34{} +public interface I36 : I35{} +public interface I37 : I36{} +public interface I38 : I37{} +public interface I39 : I38{} +public interface I40 : I39{} +public interface I41 : I40{} +public interface I42 : I41{} +public interface I43 : I42{} +public interface I44 : I43{} +public interface I45 : I44{} +public interface I46 : I45{} +public interface I47 : I46{} +public interface I48 : I47{} +public interface I49 : I48{} +public interface I50 : I49{} +public interface I51 : I50{} +public interface I52 : I51{} +public interface I53 : I52{} +public interface I54 : I53{} +public interface I55 : I54{} +public interface I56 : I55{} +public interface I57 : I56{} +public interface I58 : I57{} +public interface I59 : I58{} +public interface I60 : I59{} +public interface I61 : I60{} +public interface I62 : I61{} +public interface I63 : I62{} +public interface I64 : I63{} +public interface I65 : I64{} +public interface I66 : I65{} +public interface I67 : I66{} +public interface I68 : I67{} +public interface I69 : I68{} +public interface I70 : I69{} +public interface I71 : I70{} +public interface I72 : I71{} +public interface I73 : I72{} +public interface I74 : I73{} +public interface I75 : I74{} +public interface I76 : I75{} +public interface I77 : I76{} +public interface I78 : I77{} +public interface I79 : I78{} +public interface I80 : I79{} +public interface I81 : I80{} +public interface I82 : I81{} +public interface I83 : I82{} +public interface I84 : I83{} +public interface I85 : I84{} +public interface I86 : I85{} +public interface I87 : I86{} +public interface I88 : I87{} +public interface I89 : I88{} +public interface I90 : I89{} +public interface I91 : I90{} +public interface I92 : I91{} +public interface I93 : I92{} +public interface I94 : I93{} +public interface I95 : I94{} +public interface I96 : I95{} +public interface I97 : I96{} +public interface I98 : I97{} +public interface I99 : I98{} +public interface I100 : I99{} diff --git a/tests/src/Loader/classloader/generics/Constraints/General/ManyGenConstraints.csproj b/tests/src/Loader/classloader/generics/Constraints/General/ManyGenConstraints.csproj new file mode 100644 index 0000000000..9976da00e8 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/General/ManyGenConstraints.csproj @@ -0,0 +1,39 @@ + + + + + ManyGenConstraints + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/General/app.config b/tests/src/Loader/classloader/generics/Constraints/General/app.config new file mode 100644 index 0000000000..e5622f77ad --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/General/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/General/project.json b/tests/src/Loader/classloader/generics/Constraints/General/project.json new file mode 100644 index 0000000000..a2e84dc340 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/General/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/Recursion/RecursiveConstraints.cs b/tests/src/Loader/classloader/generics/Constraints/Recursion/RecursiveConstraints.cs new file mode 100644 index 0000000000..8d6be3fecf --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Recursion/RecursiveConstraints.cs @@ -0,0 +1,198 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// this test case contains various types with recursive constraints + +using System; +using System.IO; +using System.Collections.Generic; +using System.Text; + + +// Test 1: Base class with recursive constraint, derived class +public class Test1 +{ + public class Base where T: Base + { + public List> selfList = new List>(); + } + + + public class Derived : Base {} + + public static void Test() + { + Derived d = new Derived(); + Base bd = d; + } +} + +// Test 2: Base interface with recursive constraint, derived class +public class Test2 +{ + public interface I where T: I{} + + public class Derived : I {} + + public static void Test() + { + Derived d = new Derived(); + I id = d; + } +} + +// Test 3: Base interface with recursive constraint, derived struct +public class Test3 +{ + public interface I where T: I{} + + public struct Derived : I {} + + public static void Test() + { + #pragma warning disable 219 + Derived d = new Derived(); + I id = d; + #pragma warning restore 219 + } +} + + +// Test 4: Base class with recursive constraint, derived generic class +public class Test4 +{ + public class Base where T: Base + { + public List> selfList = new List>(); + } + + + public class Derived : Base> {} + + public static void Test() + { + Derived> d = new Derived>(); + Base>> bdi = d; + } +} + + +// Test 5: Base interface with recursive constraint, derived generic class +public class Test5 +{ + public interface I where T: I{} + + public class Derived : I> {} + + public static void Test() + { + Derived> d = new Derived>(); + I>> idi = d; + } +} + +// Test 6: Base interface with recursive constraint, derived generic struct +public class Test6 +{ + public interface I where T: I{} + + public struct Derived : I> {} + + public static void Test() + { + #pragma warning disable 219 + Derived> d = new Derived>(); + I>> idi = d; + #pragma warning restore 219 + } +} + + +// Test 7: Base interface with recursive constraint, derived generic interface, derived generic class +public class Test7 +{ + public interface I1 where T: I1{} + + public interface I2{} + + public class Derived : I2> {} + + public static void Test() + { + Derived> d = new Derived>(); + I2>> idi = d; + } +} + +// Test 8: Base interface with recursive constraint, derived generic interface, derived generic struct +public class Test8 +{ + public interface I1 where T: I1{} + + public interface I2{} + + public struct Derived : I2> {} + + public static void Test() + { + #pragma warning disable 219 + Derived> d = new Derived>(); + I2>> idi = d; + #pragma warning restore 219 + } +} + + +class RecursiveConstraints +{ + static bool pass; + + delegate void Case(); + + static void Check(Case mytest, string testName) + { + + Console.Write(testName); + + try + { + mytest(); + + Console.WriteLine("PASS"); + } + catch (Exception e) + { + Console.WriteLine("FAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + static int Main() + { + pass = true; + + Check(new Case(Test1.Test), "Test 1: Base class with recursive constraint, derived class : "); + Check(new Case(Test2.Test), "Test 2: Base interface with recursive constraint, derived class : "); + Check(new Case(Test3.Test), "Test 3: Base interface with recursive constraint, derived struct : "); + Check(new Case(Test4.Test), "Test 4: Base class with recursive constraint, derived generic class : "); + Check(new Case(Test5.Test), "Test 5: Base interface with recursive constraint, derived generic class : "); + Check(new Case(Test6.Test), "Test 6: Base interface with recursive constraint, derived generic struct : "); + Check(new Case(Test7.Test), "Test 7: Base interface with recursive constraint, derived generic interface, derived generic class : "); + Check(new Case(Test8.Test), "Test 8: Base interface with recursive constraint, derived generic interface, derived generic struct : "); + + if (pass) + { + Console.WriteLine("All tests passed"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + } +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/Recursion/RecursiveConstraints.csproj b/tests/src/Loader/classloader/generics/Constraints/Recursion/RecursiveConstraints.csproj new file mode 100644 index 0000000000..819d134222 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Recursion/RecursiveConstraints.csproj @@ -0,0 +1,39 @@ + + + + + RecursiveConstraints + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/Recursion/app.config b/tests/src/Loader/classloader/generics/Constraints/Recursion/app.config new file mode 100644 index 0000000000..e5622f77ad --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Recursion/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/Recursion/project.json b/tests/src/Loader/classloader/generics/Constraints/Recursion/project.json new file mode 100644 index 0000000000..a2e84dc340 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Recursion/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/VSW532403.cs b/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/VSW532403.cs new file mode 100644 index 0000000000..ab51ff89be --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/VSW532403.cs @@ -0,0 +1,132 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// this test is regression test for VSW 532403. +// the first test is directly from the bug. The rest of the tests were +// added to add better coverage for this area where base type has a special +// constraint and the child has recursion in inheritance. + +using System; + +public class Test1 +{ + public class Base where T : new() + { + } + public class Derived : Base> + { + } + + public static void Test() + { + Derived m = new Derived(); + Base> m2 = new Derived(); + } +} + +public class Test2 +{ + public class Base where T : class + { + } + public class Derived : Base> + { + } + + public static void Test() + { + Derived m = new Derived(); + Base> m2 = new Derived(); + } +} + +public class Test3 +{ + public interface Base where T : struct + { + } + public struct Derived : Base> + { + } + + public static void Test() + { + #pragma warning disable 219 + Derived m = new Derived(); + Base> m2 = new Derived(); + #pragma warning restore 219 + } +} + +public class Test4 +{ + public class Base where T : class, new() + { + } + public class Derived : Base> + { + } + + public static void Test() + { + Derived m = new Derived(); + Base> m2 = new Derived(); + } +} + + + + +public class RunTests +{ + + static bool pass; + + delegate void Case(); + + static void Check(Case mytest, string testName) + { + + Console.Write(testName); + + try + { + mytest(); + + Console.WriteLine("PASS"); + } + catch (Exception e) + { + Console.WriteLine("FAIL: Caught unexpected exception: " + e); + pass = false; + } + + } + + public static int Main() + { + pass = true; + + Check(new Case(Test1.Test), "Test 1: Base class with new() constraint : "); + Check(new Case(Test2.Test), "Test 2: Base class with class constraint : "); + Check(new Case(Test3.Test), "Test 3: Base class with struct constraint : "); + Check(new Case(Test4.Test), "Test 4: Base class with class and new() constraints : "); + + + + if (pass) + { + Console.WriteLine("All tests passed"); + return 100; + } + else + { + Console.WriteLine("FAIL"); + return 101; + } + + + } +} + diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/VSW532403.csproj b/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/VSW532403.csproj new file mode 100644 index 0000000000..16e91e6995 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/VSW532403.csproj @@ -0,0 +1,39 @@ + + + + + VSW532403 + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/app.config b/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/app.config new file mode 100644 index 0000000000..e5622f77ad --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/project.json b/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/project.json new file mode 100644 index 0000000000..a2e84dc340 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/532403/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/app.config b/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/app.config new file mode 100644 index 0000000000..e5622f77ad --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/bug62403.cs b/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/bug62403.cs new file mode 100644 index 0000000000..aefde9b58c --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/bug62403.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + + +class TestClass +{ + public static void N() where U : V { } + + public static void M() where U : V + { + N(); + } + + public static int Main() + { + try { + M(); + Console.WriteLine("PASS"); + return 100; + } catch (Exception e) + { + Console.WriteLine("CATCH UNEXPECTED EXCEPTION: " + e.ToString()); + Console.WriteLine("FAIL"); + return 99; + } + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/bug62403.csproj b/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/bug62403.csproj new file mode 100644 index 0000000000..fede291648 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/bug62403.csproj @@ -0,0 +1,39 @@ + + + + + bug62403 + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/project.json b/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/project.json new file mode 100644 index 0000000000..a2e84dc340 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/ddb62403/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/app.config b/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/app.config new file mode 100644 index 0000000000..e5622f77ad --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/dev10_512868.cs b/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/dev10_512868.cs new file mode 100644 index 0000000000..6b87e6e901 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/dev10_512868.cs @@ -0,0 +1,188 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +//Dev10 bug #512868: Invalid context used for generic types during constraint verification leads to BadImageFormatException + +using System; + + +public class GenericNode +{ + public GenericNode() + { + } +} + +public interface IFactory + where TNode : GenericNode +{ +} + +public static class FactoryGenerator + where TNode : GenericNode +{ + public static IFactory Instance + { + get { return null; } + } +} + +public class ItemX : InternalItemServices +{ + public ItemX() + : base() + { + } +} + +public class ContainerX : InternalContainerServices +{ + public ContainerX() + : base() + { + } +} + +public abstract class InternalItemServices : ExternalItemServices + where TContainer : GenericNode + where TItem : InternalItemServices +{ + protected InternalItemServices() + : base(FactoryGenerator.Instance, FactoryGenerator.Instance) + { + + } +} + +public abstract class ExternalItemServices : GenericNode + where TContainer : GenericNode + where TItem : GenericNode +{ + protected ExternalItemServices(IFactory containerFactory, IFactory itemFactory) + : base() + { + } +} + +public abstract class ExternalContainerServices : GenericNode + where TContainer : GenericNode + where TItem : ExternalItemServices +{ + protected ExternalContainerServices(IFactory itemFactory) + : base() + { + } +} +public abstract class InternalContainerServices : ExternalContainerServices + where TContainer : GenericNode + where TItem : ExternalItemServices +{ + protected InternalContainerServices() + : base(FactoryGenerator.Instance) + { + } +} + +class Test +{ + static int Main(string[] args) + { + ItemX treeItem = new ItemX(); + + Console.WriteLine("Pass"); + return 100; + } +} + + +// The inheritance relationships here are a little hard to follow, however +// they are valid and in fact map to conceivable usage models. +// +// Consider a tree structure with the following properties: +// +// - All tree elements derive from a GenericNode type. +// +// - The fundamental tree element is an `item'. The children of an item can +// be other items or containers. +// +// - The children of `containers' can only be items, which can in turn have +// additional children of item or container type. +// +// Say that each tree instance is built using exactly one item type and +// exactly one corresponding container type. This means the tree structure is +// parameterized on the pair. +// +// The hierarchy shape in this testcase could be used to provide services for +// a instance of the tree. +// ------------ +// +// // Generates objects of type TNode. +// IFactory +// where TNode: GenericNode +// +// +// // Static class exposing a property returning a factory interface for a +// // specific GenericNode subtype. +// FactoryGenerator +// where TNode: GenericNode +// +// IFactory Factory { get; } +// +// +// // Implements this item, inheriting base types parameterized on an arbitrary +// // pair that implement common operations that can be applied +// // to the specified item in the context of that pair. +// ItemX : InternalItemServices +// +// // Implements one level of item services. The item type is constrained to +// // be a subclass of this type. This might be useful for various reasons +// // (e.g., so that routines here can access private InternalItemServices +// // members in any TItem objects that are passed in). +// InternalItemServices : ExternalItemServices +// where TContainer: GenericNode +// where TItem: InternalItemServices (i.e., is the type of a subclass) +// +// // Pass factories to the base class for both the container and item +// // types. +// .ctor() : base(FactoryGenerator.Factory, FactoryGenerator.Factory) +// +// // Implements the next level of item services, leveraging container +// // and item factories passed to the .ctor (perhaps to generate child +// // nodes). +// ExternalItemServices : GenericNode +// where TContainer: GenericNode +// where TItem: GenericNode +// +// .ctor(IFactory useToBuildChildContainers, +// IFactory useToBuildChildItems) +// +// +// // Implements this container, inheriting base types parameterized on an arbitrary +// // pair that implement common operations that can be applied +// // to the specified container in the context of that pair. +// ContainerX : InternalContainerServices +// +// // Implements one level of container services. The item type is +// // constrained in a manner forcing it to in fact be an item type that +// // includes the common item services supplied for this +// // pair. +// InternalContainerServices : ExternalContainerServices +// where TContainer: GenericNode +// where TItem: ExternalItemServices +// +// // Pass an item factory to the base class. +// .ctor() : base(FactoryGenerator.Factory) +// +// // Implements the next level of container services, leveraging an item +// // factory passed to the .ctor (perhaps to generate child nodes). +// // +// // The item type is again constrained in a manner forcing it to in +// // fact be an item type that includes the common item services +// // supplied for this pair. +// ExternalContainerServices : GenericNode +// where TContainer: GenericNode +// where TItem: ExternalItemServices +// +// .ctor(IFactory useToBuildChildItems) +// diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/dev10_512868.csproj b/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/dev10_512868.csproj new file mode 100644 index 0000000000..325527c1d7 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/dev10_512868.csproj @@ -0,0 +1,39 @@ + + + + + dev10_512868 + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/project.json b/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/project.json new file mode 100644 index 0000000000..a2e84dc340 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/dev10_512868/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/app.config b/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/app.config new file mode 100644 index 0000000000..e5622f77ad --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/project.json b/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/project.json new file mode 100644 index 0000000000..a2e84dc340 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/project.json @@ -0,0 +1,35 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.0.10", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/vsw609874.cs b/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/vsw609874.cs new file mode 100644 index 0000000000..52dc583df6 --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/vsw609874.cs @@ -0,0 +1,37 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleApplication3 +{ + class Program + { + static int Main(string[] args) + { + try{ + Repro(null); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + Console.WriteLine("FAIL"); + return 99; + } + Console.WriteLine("PASS"); + return 100; + } + + static void Repro(B b) + where T : Program + { + } + + } + + class A { } + class B where T : class { } +} diff --git a/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/vsw609874.csproj b/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/vsw609874.csproj new file mode 100644 index 0000000000..ac3d96b95f --- /dev/null +++ b/tests/src/Loader/classloader/generics/Constraints/Regressions/vsw609874/vsw609874.csproj @@ -0,0 +1,39 @@ + + + + + vsw609874 + Debug + AnyCPU + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7a9bfb7d + true + false + Exe + BuildAndRun + 0 + + + + + False + + + + + + + + + + + + + + + + + -- cgit v1.2.3