Mercurial > hg > openjdk > jdk8 > langtools
changeset 1945:af80273f630a
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
author | mcimadamore |
---|---|
date | Mon, 12 Aug 2013 17:28:31 +0100 |
parents | f7f271bd74a2 |
children | 32b6a99cc74e |
files | src/share/classes/com/sun/tools/javac/code/Type.java src/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/lambda/8021567/T8021567.java test/tools/javac/lambda/8021567/T8021567.out test/tools/javac/lambda/8021567/T8021567b.java |
diffstat | 5 files changed, 75 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Type.java Mon Aug 12 17:25:07 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Mon Aug 12 17:28:31 2013 +0100 @@ -1525,7 +1525,7 @@ } protected void addBound(InferenceBound ib, Type bound, Types types, boolean update) { - Type bound2 = toTypeVarMap.apply(bound); + Type bound2 = toTypeVarMap.apply(bound).baseType(); List<Type> prevBounds = bounds.get(ib); for (Type b : prevBounds) { //check for redundancy - use strict version of isSameType on tvars
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Aug 12 17:25:07 2013 +0100 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Aug 12 17:28:31 2013 +0100 @@ -2395,7 +2395,7 @@ ResultInfo bodyResultInfo = lambdaType.getReturnType() == Type.recoveryType ? recoveryInfo : - new LambdaResultInfo(lambdaType.getReturnType(), funcContext); + new ResultInfo(VAL, lambdaType.getReturnType(), funcContext); localEnv.info.returnResult = bodyResultInfo; Log.DeferredDiagnosticHandler lambdaDeferredHandler = new Log.DeferredDiagnosticHandler(log); @@ -2602,28 +2602,6 @@ } } - class LambdaResultInfo extends ResultInfo { - - LambdaResultInfo(Type pt, CheckContext checkContext) { - super(VAL, pt, checkContext); - } - - @Override - protected Type check(DiagnosticPosition pos, Type found) { - return super.check(pos, found.baseType()); - } - - @Override - protected ResultInfo dup(CheckContext newContext) { - return new LambdaResultInfo(pt, newContext); - } - - @Override - protected ResultInfo dup(Type newPt) { - return new LambdaResultInfo(newPt, checkContext); - } - } - /** * Lambda compatibility. Check that given return types, thrown types, parameter types * are compatible with the expected functional interface descriptor. This means that:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/8021567/T8021567.java Mon Aug 12 17:28:31 2013 +0100 @@ -0,0 +1,26 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8021567 + * @summary Javac doesn't report "java: reference to method is ambiguous" any more + * @compile/fail/ref=T8021567.out -XDrawDiagnostics T8021567.java + */ + +class T8021567 { + + interface I_int { int m(); } + + interface I_char { char m(); } + + interface I_byte { byte m(); } + + void m(I_byte b) { } + void m(I_char b) { } + void m(I_int b) { } + + void test() { + m(() -> 1); //ambiguous + m(() -> 256); //ok - only method(I_int) applicable + m(() -> { int i = 1; return i; }); //ok - only method(I_int) applicable + m(() -> { int i = 256; return i; }); //ok - only method(I_int) applicable + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/8021567/T8021567.out Mon Aug 12 17:28:31 2013 +0100 @@ -0,0 +1,2 @@ +T8021567.java:21:9: compiler.err.ref.ambiguous: m, kindname.method, m(T8021567.I_byte), T8021567, kindname.method, m(T8021567.I_char), T8021567 +1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/8021567/T8021567b.java Mon Aug 12 17:28:31 2013 +0100 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8021567 + * @summary Javac doesn't report "java: reference to method is ambiguous" any more + */ + +public class T8021567b { + + interface SAM { + int m(); + } + + public static void main(String argv[]) { + test(); + } + + static boolean test() { + final int i = 0; + SAM s = () -> i; + return (s.m() == 0); + } +}