Bug in overload disambiguation / inference
Vicente-Arturo Romero-Zaldivar
vicente.romero at oracle.com
Tue Feb 25 08:30:54 PST 2014
Hi,
We are just modifying this part of the compiler, bug entry:
https://bugs.openjdk.java.net/browse/JDK-8029718
So the compiler's output for some of these examples may change. I will
modify the bug entry to track also this test case.
The assertion error is probably a separate bug, I have filed bug entry
https://bugs.openjdk.java.net/browse/JDK-8035761, to track it.
Thanks,
Vicente
On 23/02/14 20:39, Zhong Yu wrote:
> Note that this line doesn't compile either:
>
> run( (O t)->{ throw new Exception(); });
>
> I think this line is not supposed to compile (though javac apparently
> gives the wrong error message).
>
> Zhong Yu
>
>
> On Sun, Feb 23, 2014 at 12:31 PM, Sam Pullara <spullara at gmail.com> wrote:
>> The issues center around some overloads that the library has:
>>
>> interface Function<T, V> extends PartialFunction<T, V> {
>> V apply(T paramT);
>> }
>>
>> interface PartialFunction<T, V> {
>> V apply(T paramT) throws Exception;
>> }
>>
>> interface O {}
>>
>> static <T, V> void run(Function<? super O, V> function) {}
>> static <T, V> void run(PartialFunction<? super O, V> function) {}
>>
>> (full code here: https://gist.github.com/spullara/9175196)
>>
>> Calling the method like this:
>>
>> run(t -> t.toString())
>>
>> causes an assertion error in the compiler (b129). I'm assuming that is just
>> a bug. The problem I run into is when you call it like:
>>
>> run((O t) -> t.toString())
>>
>> which results in
>>
>> java: reference to run is ambiguous
>> both method <T,V>run(spullara.ExceptionInferenceBug.Function<? super
>> spullara.ExceptionInferenceBug.O,V>) in spullara.ExceptionInferenceBug and
>> method <T,V>run(spullara.ExceptionInferenceBug.PartialFunction<? super
>> spullara.ExceptionInferenceBug.O,V>) in spullara.ExceptionInferenceBug match
>>
>> However, if the run methods are defined as:
>>
>> static <T, V> void run(Function<O, V> function) {}
>> static <T, V> void run(PartialFunction<O, V> function) {}
>>
>> It works fine. Any ideas? Seems like the same rules should apply.
>>
>> Sam
>>
More information about the lambda-dev
mailing list