From 6651b72f904e8596d30b5b1d79aeed33629ceba3 Mon Sep 17 00:00:00 2001 From: Samuel Arzt Date: Mon, 27 Nov 2017 12:47:25 +0100 Subject: [PATCH 1/2] Added additional tests for delegate assignment/return. --- src/ILVerify/tests/ILTests/DelegateTests.il | 18 ++++- src/ILVerify/tests/ILTests/FtnTests.il | 77 +++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/src/ILVerify/tests/ILTests/DelegateTests.il b/src/ILVerify/tests/ILTests/DelegateTests.il index 97a82782569..2f0da425c12 100644 --- a/src/ILVerify/tests/ILTests/DelegateTests.il +++ b/src/ILVerify/tests/ILTests/DelegateTests.il @@ -10,7 +10,7 @@ { } -.class private auto ansi beforefieldinit C +.class private auto ansi beforefieldinit DelegateTestsType extends [System.Runtime]System.Object { // assignment from Func to Func is valid @@ -45,6 +45,22 @@ ret } + // assignment from Func to Func is invalid + .method private hidebysig instance class [System.Runtime]System.Func`1 + AssignIntFuncToByteFunc_Invalid_StackUnexpected(class [System.Runtime]System.Func`2 input) cil managed + { + ldarg.1 + ret + } + + // assignment from Func to Func is invalid + .method private hidebysig instance class [System.Runtime]System.Func`1 + AssignByteFuncToIntFunc_Invalid_StackUnexpected(class [System.Runtime]System.Func`1 input) cil managed + { + ldarg.1 + ret + } + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/src/ILVerify/tests/ILTests/FtnTests.il b/src/ILVerify/tests/ILTests/FtnTests.il index cb76a104f80..768dc39dcd4 100644 --- a/src/ILVerify/tests/ILTests/FtnTests.il +++ b/src/ILVerify/tests/ILTests/FtnTests.il @@ -106,6 +106,43 @@ } } +// Type containing test methods for delegate-assignment +.class public auto ansi beforefieldinit TestMethodsType + extends [System.Runtime]System.Object +{ + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + ldarg.0 + call instance void [System.Runtime]System.Object::.ctor() + ret + } + + .method public hidebysig static uint8 ByteReturnMethod() cil managed + { + ldc.i4.0 + ret + } + + .method public hidebysig static int32 IntReturnMethod() cil managed + { + ldc.i4.0 + ret + } + + .method public hidebysig static string StringReturnMethod() cil managed + { + ldnull + ret + } + + .method public hidebysig static object ObjectReturnMethod() cil managed + { + ldnull + ret + } +} + .class public auto ansi beforefieldinit FtnTestsType extends [System.Runtime]System.Object { @@ -363,4 +400,44 @@ callvirt instance void [System.Runtime]System.Action::Invoke() ret } + + // creating a Func from a string return method is valid + .method private hidebysig instance void ObjectFuncFromStringMethod_Valid() cil managed + { + ldnull + ldftn string TestMethodsType::StringReturnMethod() + newobj instance void class [System.Runtime]System.Func`1::.ctor(object, native int) + pop + ret + } + + // creating a Func from a object return method is invalid + .method private hidebysig instance void StringFuncFromObjectMethod_Invalid_DelegateCtor() cil managed + { + ldnull + ldftn object TestMethodsType::ObjectReturnMethod() + newobj instance void class [System.Runtime]System.Func`1::.ctor(object, native int) + pop + ret + } + + // creating a Func from an int return method is invalid + .method private hidebysig instance void ByteFuncFromIntMethod_Invalid_DelegateCtor() cil managed + { + ldnull + ldftn int32 TestMethodsType::IntReturnMethod() + newobj instance void class [System.Runtime]System.Func`1::.ctor(object, native int) + pop + ret + } + + // creating a Func from a byte return method is invalid + .method private hidebysig instance void IntFuncFromByteMethod_Invalid_DelegateCtor() cil managed + { + ldnull + ldftn uint8 TestMethodsType::ByteReturnMethod() + newobj instance void class [System.Runtime]System.Func`1::.ctor(object, native int) + pop + ret + } } From cba1f7c8e462661f7194cfc2df728d14e250be5a Mon Sep 17 00:00:00 2001 From: Samuel Arzt Date: Mon, 27 Nov 2017 21:07:49 +0100 Subject: [PATCH 2/2] Added ftn/delegate test cases for byte/int parameters and enums. --- src/ILVerify/tests/ILTests/DelegateTests.il | 32 ++++++++++++ src/ILVerify/tests/ILTests/FtnTests.il | 55 +++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/src/ILVerify/tests/ILTests/DelegateTests.il b/src/ILVerify/tests/ILTests/DelegateTests.il index 2f0da425c12..12ef7c57afe 100644 --- a/src/ILVerify/tests/ILTests/DelegateTests.il +++ b/src/ILVerify/tests/ILTests/DelegateTests.il @@ -10,6 +10,14 @@ { } +.class public auto ansi sealed ByteEnum + extends [System.Runtime]System.Enum +{ + .field public specialname rtspecialname uint8 value__ + .field public static literal valuetype ByteEnum A = uint8(0) + .field public static literal valuetype ByteEnum B = uint8(0) +} + .class private auto ansi beforefieldinit DelegateTestsType extends [System.Runtime]System.Object { @@ -61,6 +69,30 @@ ret } + // assignment from Func to Func is invalid + .method private hidebysig instance class [System.Runtime]System.Func`1 + AssignByteActionToIntAction_Invalid_StackUnexpected(class [System.Runtime]System.Func`1 input) cil managed + { + ldarg.1 + ret + } + + // assignment from Action to Action is invalid + .method private hidebysig instance class [System.Runtime]System.Action`1 + AssignByteActionToIntAction_Invalid_StackUnexpected(class [System.Runtime]System.Action`1 input) cil managed + { + ldarg.1 + ret + } + + // assignment from Action to Action is invalid + .method private hidebysig instance class [System.Runtime]System.Action`1 + AssignByteActionToByteEnumAction_Invalid_StackUnexpected(class [System.Runtime]System.Action`1 input) cil managed + { + ldarg.1 + ret + } + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { diff --git a/src/ILVerify/tests/ILTests/FtnTests.il b/src/ILVerify/tests/ILTests/FtnTests.il index 768dc39dcd4..c3a0aec451d 100644 --- a/src/ILVerify/tests/ILTests/FtnTests.il +++ b/src/ILVerify/tests/ILTests/FtnTests.il @@ -124,6 +124,13 @@ ret } + .method public hidebysig static valuetype ByteEnum ByteEnumReturnMethod() cil managed + { + ldc.i4.0 + box ByteEnum + ret + } + .method public hidebysig static int32 IntReturnMethod() cil managed { ldc.i4.0 @@ -141,6 +148,24 @@ ldnull ret } + + .method public hidebysig static void ByteParamMethod(uint8 param) cil managed + { + ret + } + + .method public hidebysig static void ByteEnumParamMethod(valuetype ByteEnum param) cil managed + { + ret + } +} + +.class public auto ansi sealed ByteEnum + extends [System.Runtime]System.Enum +{ + .field public specialname rtspecialname uint8 value__ + .field public static literal valuetype ByteEnum A = uint8(0) + .field public static literal valuetype ByteEnum B = uint8(0) } .class public auto ansi beforefieldinit FtnTestsType @@ -440,4 +465,34 @@ pop ret } + + // creating a Func from a ByteEnum return method is invalid + .method private hidebysig instance void IntFuncFromByteEnumMethod_Invalid_DelegateCtor() cil managed + { + ldnull + ldftn valuetype ByteEnum TestMethodsType::ByteEnumReturnMethod() + newobj instance void class [System.Runtime]System.Func`1::.ctor(object, native int) + pop + ret + } + + // creating an Action from a method with byte parameter is invalid + .method private hidebysig instance void IntActionFromByteMethod_Invalid_DelegateCtor() cil managed + { + ldnull + ldftn void TestMethodsType::ByteParamMethod(uint8) + newobj instance void class [System.Runtime]System.Action`1::.ctor(object, native int) + pop + ret + } + + // creating an Action from a method with an enum (with underlying type byte) as parameter is invalid + .method private hidebysig instance void ByteActionFromByteEnum_Invalid_DelegateCtor() cil managed + { + ldnull + ldftn void TestMethodsType::ByteEnumParamMethod(valuetype ByteEnum) + newobj instance void class [System.Runtime]System.Action`1::.ctor(object, native int) + pop + ret + } }