提交 94865098 编写于 作者: M mcimadamore

8009459: Wrong behavior of diamond finder with source level 7

Summary: Diamond finder doesn't take into account different inference behaviors
Reviewed-by: jjg
上级 69a026c5
......@@ -2151,8 +2151,11 @@ public class Attr extends JCTree.Visitor {
ResultInfo findDiamondResult = new ResultInfo(VAL,
resultInfo.checkContext.inferenceContext().free(resultInfo.pt) ? Type.noType : pt());
Type inferred = deferredAttr.attribSpeculative(tree, env, findDiamondResult).type;
Type polyPt = allowPoly ?
syms.objectType :
clazztype;
if (!inferred.isErroneous() &&
types.isAssignable(inferred, pt().hasTag(NONE) ? syms.objectType : pt(), types.noWarnings)) {
types.isAssignable(inferred, pt().hasTag(NONE) ? polyPt : pt(), types.noWarnings)) {
String key = types.isSameType(clazztype, inferred) ?
"diamond.redundant.args" :
"diamond.redundant.args.1";
......
/*
* @test /nodynamiccopyright/
* @bug 6939780 7020044
* @bug 6939780 7020044 8009459
*
* @summary add a warning to detect diamond sites
* @author mcimadamore
* @compile/ref=T6939780.out T6939780.java -XDrawDiagnostics -XDfindDiamond
* @compile/ref=T6939780_7.out -Xlint:-options -source 7 T6939780.java -XDrawDiagnostics -XDfindDiamond
* @compile/ref=T6939780_8.out T6939780.java -XDrawDiagnostics -XDfindDiamond
*
*/
class T6939780 {
void test() {
class Foo<X extends Number> {
Foo() {}
Foo(X x) {}
}
static class Foo<X extends Number> {
Foo() {}
Foo(X x) {}
}
void testAssign() {
Foo<Number> f1 = new Foo<Number>(1);
Foo<?> f2 = new Foo<Number>();
Foo<?> f3 = new Foo<Integer>();
......@@ -22,4 +24,16 @@ class T6939780 {
Foo<?> f5 = new Foo<Number>() {};
Foo<?> f6 = new Foo<Integer>() {};
}
void testMethod() {
gn(new Foo<Number>(1));
gw(new Foo<Number>());
gw(new Foo<Integer>());
gn(new Foo<Number>(1) {});
gw(new Foo<Number>() {});
gw(new Foo<Integer>() {});
}
void gw(Foo<?> fw) { }
void gn(Foo<Number> fn) { }
}
T6939780.java:21:28: compiler.warn.diamond.redundant.args: T6939780.Foo<java.lang.Number>, T6939780.Foo<java.lang.Number>
T6939780.java:22:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
T6939780.java:30:19: compiler.warn.diamond.redundant.args: T6939780.Foo<java.lang.Number>, T6939780.Foo<java.lang.Number>
3 warnings
T6939780.java:20:33: compiler.warn.diamond.redundant.args: T6939780.Foo<java.lang.Number>, T6939780.Foo<java.lang.Number>
T6939780.java:21:28: compiler.warn.diamond.redundant.args: T6939780.Foo<java.lang.Number>, T6939780.Foo<java.lang.Number>
T6939780.java:22:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
T6939780.java:29:19: compiler.warn.diamond.redundant.args: T6939780.Foo<java.lang.Number>, T6939780.Foo<java.lang.Number>
T6939780.java:30:19: compiler.warn.diamond.redundant.args: T6939780.Foo<java.lang.Number>, T6939780.Foo<java.lang.Number>
T6939780.java:31:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
6 warnings
T6939780.java:18:33: compiler.warn.diamond.redundant.args: Foo<java.lang.Number>, Foo<java.lang.Number>
T6939780.java:19:28: compiler.warn.diamond.redundant.args: Foo<java.lang.Number>, Foo<java.lang.Number>
T6939780.java:20:28: compiler.warn.diamond.redundant.args.1: Foo<java.lang.Integer>, Foo<java.lang.Number>
3 warnings
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册