C# Extension failed to implement interface with ambiguity

Version: 8.4.96.2033

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>
    #endif
{
    #if !COOPER
    T next();
    bool hasNext();
    #endif
}

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() {}
    #endif
}

// (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?

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

Thanks, logged as bugs://75988

bugs://75988 got closed with status fixed.

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.

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

Logged as bugs://i63922.

bugs://i63922 was closed as fixed.