dotnet-sdk icon indicating copy to clipboard operation
dotnet-sdk copied to clipboard

Actor descriptions do not take interface inheritance into account

Open eNeRGy164 opened this issue 4 years ago • 2 comments

Based on:

@eNeRGy164 - can you please separate this commit from this PR and open an issue to discuss. Any behavior changes need to be really well understood.

I suspect that this is a breaking change we would not accept until the next major release as it tightens validation we're performing. We need to talk through all of the possible cases that would be impacted.

Originally posted by @rynowak in https://github.com/dapr/dotnet-sdk/pull/684#discussion_r646188069

Issue

If an interface inherits from another interface (that does inherit from IActor. The inherited methods are not detected.

This is because the Type.GetMethods method does not return inherited methods from interfaces (in contrast to classes.

This resuts in 2 effects.

  1. For inherited methods no method descriptions are generated
  2. The detection for overloads will not generate an exception when the two overloads are declared on different interfaces.

For example:

internal interface IMethodActor : IActor
{
    Task<string> GetString();

    Task MethodWithArguments(int number, bool choice, string information);
}

internal interface IOverloadedActor : IMethodActor
{
    Task<string> GetString(string parameter);
}

IOverloadedActor would be described as only having the GetString(string) method and there would not be an exception that the GetString method is overloaded.

I created an implementation that does detect method from inheritance, but this would probably be a breaking change.

eNeRGy164 avatar Jun 06 '21 22:06 eNeRGy164

@halspang - can you double check whether this is done or not?

rynowak avatar Sep 28 '21 20:09 rynowak

@rynowak - It does not appear to be done. The linked PR is just changing some messages and adding tests. One of which appears to specifically check/enforce this behavior?

public void InterfaceDescription_CreateGeneratesMethodDescriptions_WhenTypeHasTaskMethods_ButDoesNotSeeInheritedMethods()
{
    // Arrange
    Type type = typeof(IChildActor);

    // Act
    TestDescription description = new(type);

    // Assert
    using var _ = new AssertionScope();
    description.Methods.Should().NotContainNulls();
    description.Methods.Should().AllBeOfType<MethodDescription>();
    description.Methods.Should().BeEquivalentTo(
        new { Name = "GetInt" }
    );
}

halspang avatar Oct 06 '21 22:10 halspang