eclipse-archived/ceylon

type inference with overloading and generic function refs

Closed this issue · 1 comments

This code passes a reference to a generic function to an overloaded method:

interface Stream<U> {}
interface LongFunction<U> {}

interface LongStream {
    shared formal overloaded Stream<U> mapToObj<U>(LongFunction<U> fun)
            given U satisfies Object;
    shared formal overloaded Stream<U> mapToObj<U>(U fun(Integer int))
            given U satisfies Object;
}

void do(LongStream stream) {
    stream.mapToObj(identity);
}

It results in this error:

argument must be assignable to parameter 'fun' of 'mapToObj' in 'LongStream': ' => Value(Value)' is not assignable to '<Value&Object>(Integer)'

That's because "early" resolution of the overload (i.e. before type argument inference) isn't possible in this case.

But we're doing so much better with type inference and overloading these days, that this seems like a shame. I wonder if there's something I can do...

I have implemented a pretty dirty solution to this problem, which involves special-casing coercion points in the typechecker. Perhaps there's a better way, but this seems pretty reasonable for now.