8009459: Wrong behavior of diamond finder with source level 7
Summary: Diamond finder doesn't take into account different inference behaviors
Reviewed-by: jjg
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Mar 06 15:29:30 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Mar 06 15:33:17 2013 +0000
@@ -2151,8 +2151,11 @@
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";
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/diamond/6939780/T6939780.java Wed Mar 06 15:33:17 2013 +0000
@@ -0,0 +1,39 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 6939780 7020044 8009459
+ *
+ * @summary add a warning to detect diamond sites
+ * @author mcimadamore
+ * @compile/ref=T6939780_7.out -Xlint:-options -source 7 T6939780.java -XDrawDiagnostics -XDfindDiamond
+ * @compile/ref=T6939780_8.out T6939780.java -XDrawDiagnostics -XDfindDiamond
+ *
+ */
+
+class T6939780 {
+
+ 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>();
+ Foo<Number> f4 = new Foo<Number>(1) {};
+ 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) { }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/diamond/6939780/T6939780_7.out Wed Mar 06 15:33:17 2013 +0000
@@ -0,0 +1,4 @@
+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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/diamond/6939780/T6939780_8.out Wed Mar 06 15:33:17 2013 +0000
@@ -0,0 +1,7 @@
+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
--- a/langtools/test/tools/javac/generics/diamond/T6939780.java Wed Mar 06 15:29:30 2013 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/*
- * @test /nodynamiccopyright/
- * @bug 6939780 7020044
- *
- * @summary add a warning to detect diamond sites
- * @author mcimadamore
- * @compile/ref=T6939780.out T6939780.java -XDrawDiagnostics -XDfindDiamond
- *
- */
-
-class T6939780 {
-
- void test() {
- class Foo<X extends Number> {
- Foo() {}
- Foo(X x) {}
- }
- Foo<Number> f1 = new Foo<Number>(1);
- Foo<?> f2 = new Foo<Number>();
- Foo<?> f3 = new Foo<Integer>();
- Foo<Number> f4 = new Foo<Number>(1) {};
- Foo<?> f5 = new Foo<Number>() {};
- Foo<?> f6 = new Foo<Integer>() {};
- }
-}
--- a/langtools/test/tools/javac/generics/diamond/T6939780.out Wed Mar 06 15:29:30 2013 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-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