diff --git a/CodeConverter/Util/FromRoslyn/IMethodSymbolExtensions.cs b/CodeConverter/Util/FromRoslyn/IMethodSymbolExtensions.cs index 3852eb6ca..445d169c6 100644 --- a/CodeConverter/Util/FromRoslyn/IMethodSymbolExtensions.cs +++ b/CodeConverter/Util/FromRoslyn/IMethodSymbolExtensions.cs @@ -23,12 +23,12 @@ public static bool CompatibleSignatureToDelegate(this IMethodSymbol method, INam return false; } - if (!method.ReturnType.InheritsFromOrEquals(invoke.ReturnType)) { + if (!method.ReturnType.InheritsFromOrEquals(invoke.ReturnType, true)) { return false; } for (var i = 0; i < method.Parameters.Length; i++) { - if (!invoke.Parameters[i].Type.InheritsFromOrEquals(method.Parameters[i].Type)) { + if (!invoke.Parameters[i].Type.InheritsFromOrEquals(method.Parameters[i].Type, true)) { return false; } } diff --git a/Tests/CSharp/ExpressionTests/ExpressionTests.cs b/Tests/CSharp/ExpressionTests/ExpressionTests.cs index 1002400dd..1595a234d 100644 --- a/Tests/CSharp/ExpressionTests/ExpressionTests.cs +++ b/Tests/CSharp/ExpressionTests/ExpressionTests.cs @@ -1440,6 +1440,76 @@ private void TestMethod() }"); } + [Fact] + public async Task Issue1148_AddressOfSignatureCompatibilityAsync() + { + await TestConversionVisualBasicToCSharpAsync(@" +Imports System + +Public Class Issue1148 + Public Shared FuncClass As Func(Of TestObjClass) = AddressOf FunctionReturningClass + Public Shared FuncBaseClass As Func(Of TestBaseObjClass) = AddressOf FunctionReturningClass + Public Shared FuncInterface As Func(Of ITestObj) = AddressOf FunctionReturningClass + Public Shared FuncInterfaceParam As Func(Of ITestObj, ITestObj) = AddressOf CastObj + Public Shared FuncClassParam As Func(Of TestObjClass, ITestObj) = AddressOf CastObj + + Public Shared Function FunctionReturningClass() As TestObjClass + Return New TestObjClass() + End Function + + Public Shared Function CastObj(obj As ITestObj) As TestObjClass + Return CType(obj, TestObjClass) + End Function + +End Class + +Public Class TestObjClass + Inherits TestBaseObjClass + Implements ITestObj +End Class + +Public Class TestBaseObjClass +End Class + +Public Interface ITestObj +End Interface +", @" +using System; + +public partial class Issue1148 +{ + public static Func FuncClass = FunctionReturningClass; + public static Func FuncBaseClass = FunctionReturningClass; + public static Func FuncInterface = FunctionReturningClass; + public static Func FuncInterfaceParam = CastObj; + public static Func FuncClassParam = CastObj; + + public static TestObjClass FunctionReturningClass() + { + return new TestObjClass(); + } + + public static TestObjClass CastObj(ITestObj obj) + { + return (TestObjClass)obj; + } + +} + +public partial class TestObjClass : TestBaseObjClass, ITestObj +{ +} + +public partial class TestBaseObjClass +{ +} + +public partial interface ITestObj +{ +} +"); + } + [Fact] public async Task LambdaImmediatelyExecutedAsync() {