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

Invoking default interface method implementation from a selected interface #14127

Closed
damirarh opened this issue Aug 31, 2019 — with docs.microsoft.com · 4 comments
Closed
Assignees
Labels
by-design dotnet-csharp/svc Pri0 Indicates issues or PRs that are critical priority ⌚ Not Triaged Not triaged

Comments

Copy link
Contributor

Let's say I have the following rather contrived scenario:

interface I0
{
    string Method()
    {
        return "I0";
    }
}

interface I1 : I0
{
    string I0.Method()
    {
        return "I1";
    }
}

interface I2 : I0
{
    string I0.Method()
    {
        return "I2";
    }
}

Now I want a class to implement both I1 and I2:

class C12 : I1, I2
{
}

As expected, I get the following compiler error:

> Interface member 'I0.Method()' does not have a most specific implementation. Neither 'I1.I0.Method()', nor 'I2.I0.Method()' are most specific.

I can resolve this if I provide my own implementation. Inside it, how could I invoke the implementation from one of the interfaces, e.g. I1? I'm pretty sure the following syntax used to work in a previous preview:

class C12 : I1, I2
{
    string I0.Method()
    {
        return base(I1).Method();
    }
}

However, now the compiler complains:

> Use of keyword 'base' is not valid in this context

What is the correct syntax to invoke the default method implementation in interface I1? I can't find it documented anywhere.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@BillWagner BillWagner added the Pri0 Indicates issues or PRs that are critical priority label Sep 9, 2019
@BillWagner BillWagner added this to the September 2019 milestone Sep 9, 2019
@BillWagner BillWagner self-assigned this Sep 9, 2019
@BillWagner
Copy link
Member

Thanks for writing this @damirarh

I'll make sure to get it updated this month.

I did a quick search, and I can't find the LDM notes where this was updated. @agocke @jcouv Can you point me to the correct updates?

@BillWagner BillWagner added needs-more-info Needs more info from OP. Auto-closed after 2 weeks if no response. [org][resolution] waiting-on-feedback Waiting for feedback from SMEs before they can be merged and removed needs-more-info Needs more info from OP. Auto-closed after 2 weeks if no response. [org][resolution] labels Sep 10, 2019
@jcouv
Copy link
Member

jcouv commented Sep 10, 2019

Yes, the error for ambiguous implementation is expected (notes).

For the base(I1) question, the functionality was removed from C# 8. Here's the PR. This was decided in the 04-29 meeting.
We have a follow-up championed issue (currently considered for C# 9).

@BillWagner BillWagner removed ⌚ Not Triaged Not triaged waiting-on-feedback Waiting for feedback from SMEs before they can be merged labels Sep 11, 2019
@BillWagner
Copy link
Member

Thanks @jcouv

I'll review the doc carefully and make sure it reflects the current planning.

@BillWagner
Copy link
Member

I did review the tagged article, and it's correct with respect to the C# 8.0 implementation.

Continued discussion should be related to the dotnet/csharplang#2337

Closing this as by-design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
by-design dotnet-csharp/svc Pri0 Indicates issues or PRs that are critical priority ⌚ Not Triaged Not triaged
Projects
None yet
Development

No branches or pull requests

4 participants