Skip to content

Commit 6e0e0e9

Browse files
Merge pull request #1153 from gaschd/issue-1148-incompatible-delegate-signature
AddressOf does not wrap compatible signatures in lambdas anymore
2 parents bb5c35f + 552f89d commit 6e0e0e9

2 files changed

Lines changed: 72 additions & 2 deletions

File tree

CodeConverter/Util/FromRoslyn/IMethodSymbolExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public static bool CompatibleSignatureToDelegate(this IMethodSymbol method, INam
2323
return false;
2424
}
2525

26-
if (!method.ReturnType.InheritsFromOrEquals(invoke.ReturnType)) {
26+
if (!method.ReturnType.InheritsFromOrEquals(invoke.ReturnType, true)) {
2727
return false;
2828
}
2929

3030
for (var i = 0; i < method.Parameters.Length; i++) {
31-
if (!invoke.Parameters[i].Type.InheritsFromOrEquals(method.Parameters[i].Type)) {
31+
if (!invoke.Parameters[i].Type.InheritsFromOrEquals(method.Parameters[i].Type, true)) {
3232
return false;
3333
}
3434
}

Tests/CSharp/ExpressionTests/ExpressionTests.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,76 @@ private void TestMethod()
14401440
}");
14411441
}
14421442

1443+
[Fact]
1444+
public async Task Issue1148_AddressOfSignatureCompatibilityAsync()
1445+
{
1446+
await TestConversionVisualBasicToCSharpAsync(@"
1447+
Imports System
1448+
1449+
Public Class Issue1148
1450+
Public Shared FuncClass As Func(Of TestObjClass) = AddressOf FunctionReturningClass
1451+
Public Shared FuncBaseClass As Func(Of TestBaseObjClass) = AddressOf FunctionReturningClass
1452+
Public Shared FuncInterface As Func(Of ITestObj) = AddressOf FunctionReturningClass
1453+
Public Shared FuncInterfaceParam As Func(Of ITestObj, ITestObj) = AddressOf CastObj
1454+
Public Shared FuncClassParam As Func(Of TestObjClass, ITestObj) = AddressOf CastObj
1455+
1456+
Public Shared Function FunctionReturningClass() As TestObjClass
1457+
Return New TestObjClass()
1458+
End Function
1459+
1460+
Public Shared Function CastObj(obj As ITestObj) As TestObjClass
1461+
Return CType(obj, TestObjClass)
1462+
End Function
1463+
1464+
End Class
1465+
1466+
Public Class TestObjClass
1467+
Inherits TestBaseObjClass
1468+
Implements ITestObj
1469+
End Class
1470+
1471+
Public Class TestBaseObjClass
1472+
End Class
1473+
1474+
Public Interface ITestObj
1475+
End Interface
1476+
", @"
1477+
using System;
1478+
1479+
public partial class Issue1148
1480+
{
1481+
public static Func<TestObjClass> FuncClass = FunctionReturningClass;
1482+
public static Func<TestBaseObjClass> FuncBaseClass = FunctionReturningClass;
1483+
public static Func<ITestObj> FuncInterface = FunctionReturningClass;
1484+
public static Func<ITestObj, ITestObj> FuncInterfaceParam = CastObj;
1485+
public static Func<TestObjClass, ITestObj> FuncClassParam = CastObj;
1486+
1487+
public static TestObjClass FunctionReturningClass()
1488+
{
1489+
return new TestObjClass();
1490+
}
1491+
1492+
public static TestObjClass CastObj(ITestObj obj)
1493+
{
1494+
return (TestObjClass)obj;
1495+
}
1496+
1497+
}
1498+
1499+
public partial class TestObjClass : TestBaseObjClass, ITestObj
1500+
{
1501+
}
1502+
1503+
public partial class TestBaseObjClass
1504+
{
1505+
}
1506+
1507+
public partial interface ITestObj
1508+
{
1509+
}
1510+
");
1511+
}
1512+
14431513
[Fact]
14441514
public async Task LambdaImmediatelyExecutedAsync()
14451515
{

0 commit comments

Comments
 (0)