Skip to content

Commit

Permalink
Merge pull request #1153 from gaschd/issue-1148-incompatible-delegate…
Browse files Browse the repository at this point in the history
…-signature

AddressOf does not wrap compatible signatures in lambdas anymore
  • Loading branch information
GrahamTheCoder authored Nov 9, 2024
2 parents bb5c35f + 552f89d commit 6e0e0e9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CodeConverter/Util/FromRoslyn/IMethodSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
70 changes: 70 additions & 0 deletions Tests/CSharp/ExpressionTests/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestObjClass> FuncClass = FunctionReturningClass;
public static Func<TestBaseObjClass> FuncBaseClass = FunctionReturningClass;
public static Func<ITestObj> FuncInterface = FunctionReturningClass;
public static Func<ITestObj, ITestObj> FuncInterfaceParam = CastObj;
public static Func<TestObjClass, ITestObj> 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()
{
Expand Down

0 comments on commit 6e0e0e9

Please sign in to comment.