C# Extension failed to implement interface with ambiguity

(James Esword) #1


Just found Extension for C# is available in 8.4 beta, and have a try to refactor my cross platform Iterable/Iterator with this awesome feature.

Here’s a problem with .NET/UWP:

public interface Iterator<T>
    #if COOPER
    : java.util.Iterator<T>
    #elif ECHOES
    : IEnumerator<T>
    #if !COOPER
    T next();
    bool hasNext();

public __extension class IteratorDefault<T> : Iterator<T>{
    #if COOPER
    public void remove() {}

    #elif ECHOES

    // (E170) "implements" type "IEnumerator" is not in the inheritance list of this type
    public object IEnumerator.Current => next();
    public T Current => next();
    public bool MoveNext() => hasNext();
    public void Reset() {}
    public void Dispose() {}

// (E181) Property "Current: Object" getter not implemented as required for interface "IEnumerator"
public class TestIterator : Iterator<string>{
    public string next() => null;
    public bool hasNext() => false;

The Extension is indeed able to add default implementation for interface, but it seems can’t recognize inheritance with ambiguity. Is there a way to fix that?

(Carlo Kok) #2

Not yet. I have to think about it. But i’ll log it.

(RemObjects) #3

Thanks, logged as bugs://75988

(RemObjects) #4

bugs://75988 got closed with status fixed.

(Carlo Kok) #5

Oke so had an idea for this one, you really need another extension class (For Echoes only) like:

public __extension class IteratorDefaultNG<T> : Iterator<T> {
    public object Current => next();

Now this won’t work with the build you have due to a bug. I fixed that bug so next weeks build will have this.

(James Esword) #6

The solution is ok! I will try it :ok_hand: