Grain code generation fails when using default interface methods
- Dominant language
- C#
- Stars
- 10.9k
- Forks
- 2.1k
- Avg merge
- 14h 42m
- Merged PRs (30d)
- 354
Description
# The issue
When a grain is implemented in the following manner the code generation step during build fails.
```csharp
public interface ITestInterface {
Task Method(object o);
}
public interface ITestInterface : ITestInterface {
Task Method(T t);
Task ITestInterface.Method(object o) => Method((T)t);
}
public interface ITestGrain : IGrainWithGuidKey, ITestInterface { }
```
The failure is represented by the following two errors:
| Code | Description |
|-------|--------------|
| [CS0538](https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0538) | 'ITestInterface.OrleansInterfaceBugRepro.ITestInterface' in explicit interface declaration is not an interface |
| [CS0426](https://docs.microsoft.com/en-us/dotnet/csharp/misc/CS0426) | The type name 'OrleansInterfaceBugRepro' does not exist in the type 'ITestInterface' |
# Reproduction
A minimal reproduction of this issue can be found at https://github.com/corstian/OrleansDefaultInterfaceMethodBugRepro. I was able to reproduce this issue on both 3.6.0 and 4.0.0-preview1.
# What happens
Orleans generates a `OrleansCodeGenTestGrainReference` class implementing the defined interfaces. Three invokers are generated:
1. `ITestInterface.Method(object o)`
2. `ITestInterface.Method(T t)`
3. The default interface method providing an implementation for `ITestInterface.Method(object o)` from within `ITestInterface`. The method as is generated fails due to syntax errors. An example of the resulting method signature is as follows:
```csharp
global::System.Threading.Tasks.Task global::OrleansInterfaceBugRepro.ITestInterface.OrleansInterfaceBugRepro.ITestInterface.Method(object t0)
```
# Expected behaviour
Solely `ITestInterface.Method(T t)` would be generated. The CLR should be able to use these interface to resolve invocations of these interface methods to the implemented `ITestInterface.Method(T t)` method.
Contributor guide
Assessment
This issue has not been assessed yet.