Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude explicitly implemented interface methods from proxy #8992

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should also check for a body, explicit impls can be used for reabstraction in interface type hierarchies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure it's necessary: the generated proxy should implement every method explicitly (I added a comment below this line). Any overrides should take effect on the callee side naturally (correct me if you find that I'm wrong here)

{
// 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
Loading