8021567: Javac doesn't report \"java: reference to method is ambiguous\" any more

Mon, 12 Aug 2013 17:28:31 +0100

author
mcimadamore
date
Mon, 12 Aug 2013 17:28:31 +0100
changeset 1946
af80273f630a
parent 1945
f7f271bd74a2
child 1947
32b6a99cc74e

8021567: Javac doesn't report \"java: reference to method is ambiguous\" any more
Summary: Javac incorrectly forgets about constant folding results within lambdas
Reviewed-by: jjg, vromero

src/share/classes/com/sun/tools/javac/code/Type.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/8021567/T8021567.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/8021567/T8021567.out file | annotate | diff | comparison | revisions
test/tools/javac/lambda/8021567/T8021567b.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java	Mon Aug 12 17:25:07 2013 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Mon Aug 12 17:28:31 2013 +0100
     1.3 @@ -1525,7 +1525,7 @@
     1.4          }
     1.5  
     1.6          protected void addBound(InferenceBound ib, Type bound, Types types, boolean update) {
     1.7 -            Type bound2 = toTypeVarMap.apply(bound);
     1.8 +            Type bound2 = toTypeVarMap.apply(bound).baseType();
     1.9              List<Type> prevBounds = bounds.get(ib);
    1.10              for (Type b : prevBounds) {
    1.11                  //check for redundancy - use strict version of isSameType on tvars
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Aug 12 17:25:07 2013 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Aug 12 17:28:31 2013 +0100
     2.3 @@ -2395,7 +2395,7 @@
     2.4  
     2.5              ResultInfo bodyResultInfo = lambdaType.getReturnType() == Type.recoveryType ?
     2.6                  recoveryInfo :
     2.7 -                new LambdaResultInfo(lambdaType.getReturnType(), funcContext);
     2.8 +                new ResultInfo(VAL, lambdaType.getReturnType(), funcContext);
     2.9              localEnv.info.returnResult = bodyResultInfo;
    2.10  
    2.11              Log.DeferredDiagnosticHandler lambdaDeferredHandler = new Log.DeferredDiagnosticHandler(log);
    2.12 @@ -2602,28 +2602,6 @@
    2.13              }
    2.14          }
    2.15  
    2.16 -        class LambdaResultInfo extends ResultInfo {
    2.17 -
    2.18 -            LambdaResultInfo(Type pt, CheckContext checkContext) {
    2.19 -                super(VAL, pt, checkContext);
    2.20 -            }
    2.21 -
    2.22 -            @Override
    2.23 -            protected Type check(DiagnosticPosition pos, Type found) {
    2.24 -                return super.check(pos, found.baseType());
    2.25 -            }
    2.26 -
    2.27 -            @Override
    2.28 -            protected ResultInfo dup(CheckContext newContext) {
    2.29 -                return new LambdaResultInfo(pt, newContext);
    2.30 -            }
    2.31 -
    2.32 -            @Override
    2.33 -            protected ResultInfo dup(Type newPt) {
    2.34 -                return new LambdaResultInfo(newPt, checkContext);
    2.35 -            }
    2.36 -        }
    2.37 -
    2.38          /**
    2.39          * Lambda compatibility. Check that given return types, thrown types, parameter types
    2.40          * are compatible with the expected functional interface descriptor. This means that:
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/lambda/8021567/T8021567.java	Mon Aug 12 17:28:31 2013 +0100
     3.3 @@ -0,0 +1,26 @@
     3.4 +/*
     3.5 + * @test /nodynamiccopyright/
     3.6 + * @bug 8021567
     3.7 + * @summary Javac doesn't report "java: reference to method is ambiguous" any more
     3.8 + * @compile/fail/ref=T8021567.out -XDrawDiagnostics T8021567.java
     3.9 + */
    3.10 +
    3.11 +class T8021567 {
    3.12 +
    3.13 +    interface I_int { int m(); }
    3.14 +
    3.15 +    interface I_char { char m(); }
    3.16 +
    3.17 +    interface I_byte { byte m(); }
    3.18 +
    3.19 +    void m(I_byte b) { }
    3.20 +    void m(I_char b) { }
    3.21 +    void m(I_int b) { }
    3.22 +
    3.23 +    void test() {
    3.24 +        m(() -> 1); //ambiguous
    3.25 +        m(() -> 256); //ok - only method(I_int) applicable
    3.26 +        m(() -> { int i = 1; return i; }); //ok - only method(I_int) applicable
    3.27 +        m(() -> { int i = 256; return i; }); //ok - only method(I_int) applicable
    3.28 +    }
    3.29 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/lambda/8021567/T8021567.out	Mon Aug 12 17:28:31 2013 +0100
     4.3 @@ -0,0 +1,2 @@
     4.4 +T8021567.java:21:9: compiler.err.ref.ambiguous: m, kindname.method, m(T8021567.I_byte), T8021567, kindname.method, m(T8021567.I_char), T8021567
     4.5 +1 error
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/lambda/8021567/T8021567b.java	Mon Aug 12 17:28:31 2013 +0100
     5.3 @@ -0,0 +1,45 @@
     5.4 +/*
     5.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.23 + * or visit www.oracle.com if you need additional information or have any
    5.24 + * questions.
    5.25 + */
    5.26 +
    5.27 +/*
    5.28 + * @test
    5.29 + * @bug 8021567
    5.30 + * @summary Javac doesn't report "java: reference to method is ambiguous" any more
    5.31 + */
    5.32 +
    5.33 +public class T8021567b {
    5.34 +
    5.35 +    interface SAM {
    5.36 +        int m();
    5.37 +    }
    5.38 +
    5.39 +    public static void main(String argv[]) {
    5.40 +        test();
    5.41 +    }
    5.42 +
    5.43 +    static boolean test() {
    5.44 +        final int i = 0;
    5.45 +        SAM s = () -> i;
    5.46 +        return (s.m() == 0);
    5.47 +    }
    5.48 +}

mercurial