diff --git a/src/ILVerify/src/ILImporter.Verify.cs b/src/ILVerify/src/ILImporter.Verify.cs index 025d2475610..ee9215a7931 100644 --- a/src/ILVerify/src/ILImporter.Verify.cs +++ b/src/ILVerify/src/ILImporter.Verify.cs @@ -1003,12 +1003,12 @@ bool IsDelegateAssignable(MethodDesc ftn, TypeDesc delegateType) for (int i = 0; i < ftnSignature.Length; i++) { - if (!IsAssignable(ftnSignature[i], delegateSignature[i])) + if (!IsAssignable(delegateSignature[i], ftnSignature[i])) return false; } // Compare return type - return IsAssignable(delegateSignature.ReturnType, ftnSignature.ReturnType); + return IsAssignable(ftnSignature.ReturnType, delegateSignature.ReturnType); } ILOpcode GetOpcodeAt(int instructionOffset) diff --git a/src/ILVerify/src/ILVerify.csproj b/src/ILVerify/src/ILVerify.csproj index d07d962fa99..27ce4fc9e98 100644 --- a/src/ILVerify/src/ILVerify.csproj +++ b/src/ILVerify/src/ILVerify.csproj @@ -3,6 +3,7 @@ Exe netcoreapp2.0;net46 + AnyCPU false true false diff --git a/src/ILVerify/tests/ILMethodTester.cs b/src/ILVerify/tests/ILMethodTester.cs index 1d5eeda163f..671bd3f915c 100644 --- a/src/ILVerify/tests/ILMethodTester.cs +++ b/src/ILVerify/tests/ILMethodTester.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection.Metadata.Ecma335; using Internal.IL; using Internal.TypeSystem.Ecma; @@ -60,7 +61,8 @@ void TestMethodsWithInvalidIL(InvalidILTestCase invalidIL) foreach (var item in invalidIL.ExpectedVerifierErrors) { - Assert.True(verifierErrors.Contains(item)); + var actual = verifierErrors.Select(e => e.ToString()); + Assert.True(verifierErrors.Contains(item), $"Actual errors where: {string.Join(',', actual)}"); } } } diff --git a/src/ILVerify/tests/ILTests/DelegateTests.il b/src/ILVerify/tests/ILTests/DelegateTests.il new file mode 100644 index 00000000000..97a82782569 --- /dev/null +++ b/src/ILVerify/tests/ILTests/DelegateTests.il @@ -0,0 +1,55 @@ +// 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.Runtime +{ +} + +.assembly DelegateTests +{ +} + +.class private auto ansi beforefieldinit C + extends [System.Runtime]System.Object +{ + // assignment from Func to Func is valid + .method private hidebysig instance class [System.Runtime]System.Func`2 + DelegateAssignmentReturn_Valid(class [System.Runtime]System.Func`2 input) cil managed + { + ldarg.1 + ret + } + + // assignment from Func to Func is valid + .method private hidebysig instance class [System.Runtime]System.Func`2 + DelegateAssignmentParameter_Valid(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`2 + DelegateAssignmentParameter_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`2 + DelegateAssignment_Invalid_StackUnexpected(class [System.Runtime]System.Func`2 input) cil managed + { + ldarg.1 + ret + } + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + ldarg.0 + call instance void [System.Runtime]System.Object::.ctor() + ret + } +}