hg: lambda/lambda/langtools: 8016175: Add bottom-up type-checking support for unambiguous method references
maurizio cimadamore
maurizio.cimadamore at oracle.com
Sat Jun 29 04:54:41 PDT 2013
On 28-Jun-13 5:59 PM, Ali Ebrahimi wrote:
> Hi Maurizio,
> In test MethodReference71 I don't get why g(this::m2) is ambiguous.
> please clarify this for me. thanks in advance.
It's not ambiguous, sorry for the typo in the test; however it's
erroneous, as the compiler doesn't have enough information to type-check
the method reference.
If, however, the method reference is unambiguous _and_ not a varargs (as
the first case), the compiler will go bottom up and 'unstick' the method
reference.
We decided against the varargs case as, in the general case, that would
require support for disjunctive type inference, and we wanted to limit
the scope of the change at this point of the release.
Thanks
Maurizio
> +class MethodReference71 {
> + interface F<X> {
> + void m(X x);
> + }
> +
> + interface G<X> {
> + Integer m(X x);
> + }
> +
> + void m1(Integer i) { }
> + void m2(Integer... i) { }
> +
> + <Z> void g(F<Z> f) { }
> + <Z> void g(G<Z> g) { }
> +
> + void test() {
> + g(this::m1); //ok
> + g(this::m2); //ambiguous (stuck!)
> + }
> +}
> Ali Ebrahimi
>
>
> On Fri, Jun 28, 2013 at 3:26 PM, <maurizio.cimadamore at oracle.com
> <mailto:maurizio.cimadamore at oracle.com>> wrote:
>
> Changeset: eda4ff70411f
> Author: mcimadamore
> Date: 2013-06-28 11:54 +0100
> URL:
> http://hg.openjdk.java.net/lambda/lambda/langtools/rev/eda4ff70411f
>
> 8016175: Add bottom-up type-checking support for unambiguous
> method references
>
> ! src/share/classes/com/sun/tools/javac/comp/Attr.java
> ! src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
> ! src/share/classes/com/sun/tools/javac/comp/Infer.java
> ! src/share/classes/com/sun/tools/javac/comp/Resolve.java
> + test/tools/javac/lambda/MethodReference68.java
> + test/tools/javac/lambda/MethodReference68.out
> + test/tools/javac/lambda/MethodReference69.java
> + test/tools/javac/lambda/MethodReference69.out
> + test/tools/javac/lambda/MethodReference70.java
> + test/tools/javac/lambda/MethodReference70.out
> + test/tools/javac/lambda/MethodReference71.java
> + test/tools/javac/lambda/MethodReference71.out
> ! test/tools/javac/lambda/TargetType60.out
>
>
>
More information about the lambda-dev
mailing list