Skip to content

Commit

Permalink
Exclude explicitly implemented interface methods from proxy (#8992)
Browse files Browse the repository at this point in the history
* Exclude ExplicitInterfaceImplementation methods

* Add comments to test types and rename to suit

---------

Co-authored-by: ReubenBond <rebond@microsoft.com>
  • Loading branch information
alrz and ReubenBond committed May 22, 2024
1 parent 3d7343e commit 63236c3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Orleans.CodeGenerator/Model/ProxyInterfaceDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ private List<ProxyMethodDescription> GetMethods()
{
foreach (var method in iface.GetDeclaredInstanceMembers<IMethodSymbol>())
{
if (method.MethodKind == MethodKind.ExplicitInterfaceImplementation)
{
// Explicit implementations can be ignored when generating a proxy.
// Proxies must implement every method explicitly to ensure faithful reproduction of the interface behavior.
// At the calling side, the explicit implementation will be called if it was not overridden by a derived type.
continue;
}

var methodDescription = CodeGenerator.GetProxyMethodDescription(InterfaceType, method: method);
result.Add(methodDescription);
}
Expand Down
25 changes: 25 additions & 0 deletions test/DefaultCluster.Tests/CodeGenTests/IRuntimeCodeGenGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@ namespace Tester.CodeGenTests
using Orleans;
using Orleans.Providers;

// Regression test for explicit interface method implementations https://github.com/dotnet/orleans/issues/8991
public interface IExplicitInterfaceMethodImplementationTestGenericBase<in T>
{
Task M(T arg);
}

public interface IExplicitInterfaceMethodImplementationTestBase : IExplicitInterfaceMethodImplementationTestGenericBase<object>;

public interface IExplicitInterfaceMethodImplementationTestDerived : IExplicitInterfaceMethodImplementationTestBase, IExplicitInterfaceMethodImplementationTestGenericBase<string>
{
Task IExplicitInterfaceMethodImplementationTestGenericBase<object>.M(object obj) => M(obj);
}

public interface IExplicitInterfaceMethodImplementationTestImplementation : IExplicitInterfaceMethodImplementationTestDerived, IGrainWithGuidKey;

public class ExplicitInterfaceMethodImplementationTestGrain : Grain, IExplicitInterfaceMethodImplementationTestImplementation
{
public Task M(string arg)
{
throw new NotImplementedException();
}
}

// End regression test for https://github.com/dotnet/orleans/issues/8991

public interface IGrainWithGenericMethods : IGrainWithGuidKey
{
Task<Type[]> GetTypesExplicit<T, U, V>();
Expand Down

0 comments on commit 63236c3

Please sign in to comment.