Skip to content

Example in 18.4.6 is incorrect: calling an ambiguous-looking interface member can work... #1062

@jskeet

Description

@jskeet

We have the following example in 18.4.6 (which isn't tested as it's marked for "needs review"):

interface IList
{
    int Count { get; set; }
}

interface ICounter
{
    void Count(int i);
}

interface IListCounter : IList, ICounter {}

class C
{
    void Test(IListCounter x)
    {
        x.Count(1);             // Error
        x.Count = 1;            // Error: cannot assign to a method group
        ((IList)x).Count = 1;   // Ok, invokes IList.Count.set
        ((ICounter)x).Count(1); // Ok, invokes ICounter.Count
    }
}

With text:

In the following code [...] the first two statements cause compile-time errors because the member lookup (§12.5) of Count in IListCounter is ambiguous.

However, the first of these statements works when running the example tester. It's only the second which fails (CS1656: Cannot assign to 'Count' because it is a 'method group').

Has interface member lookup changed in a way that has made the first statement become valid, or has the spec always just been wrong?

Metadata

Metadata

Assignees

Labels

type: bugThe Standard does not describe the language as intended or implemented

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions