提交 f855f0da 编写于 作者: M mcimadamore

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
上级 b8b4de0b
......@@ -1525,7 +1525,7 @@ public abstract class Type implements TypeMirror {
}
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
......
......@@ -2395,7 +2395,7 @@ public class Attr extends JCTree.Visitor {
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 @@ public class Attr extends JCTree.Visitor {
}
}
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:
......
/*
* @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
}
}
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
/*
* 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);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册