8021338: Diamond finder may mark a required type argument as unnecessary
authorjlahoda
Sun, 28 Jul 2013 10:17:45 +0200
changeset 19132 e2349c075315
parent 19131 519fa466d8ba
child 19133 aa085efaaa2e
8021338: Diamond finder may mark a required type argument as unnecessary Reviewed-by: mcimadamore
langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java
langtools/test/tools/javac/generics/diamond/6939780/T6939780.java
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Sun Jul 28 10:17:45 2013 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java	Sun Jul 28 10:17:45 2013 +0200
@@ -2195,7 +2195,9 @@
                         syms.objectType :
                         clazztype;
                 if (!inferred.isErroneous() &&
-                    types.isAssignable(inferred, pt().hasTag(NONE) ? polyPt : pt(), types.noWarnings)) {
+                    (allowPoly && pt() == Infer.anyPoly ?
+                        types.isSameType(inferred, clazztype) :
+                        types.isAssignable(inferred, pt().hasTag(NONE) ? polyPt : pt(), types.noWarnings))) {
                     String key = types.isSameType(clazztype, inferred) ?
                         "diamond.redundant.args" :
                         "diamond.redundant.args.1";
--- a/langtools/test/tools/javac/generics/diamond/6939780/T6939780.java	Sun Jul 28 10:17:45 2013 +0200
+++ b/langtools/test/tools/javac/generics/diamond/6939780/T6939780.java	Sun Jul 28 10:17:45 2013 +0200
@@ -1,6 +1,6 @@
 /*
  * @test /nodynamiccopyright/
- * @bug 6939780 7020044 8009459
+ * @bug 6939780 7020044 8009459 8021338
  *
  * @summary  add a warning to detect diamond sites
  * @author mcimadamore
@@ -36,4 +36,15 @@
 
     void gw(Foo<?> fw) { }
     void gn(Foo<Number> fn) { }
+
+    static class Foo2<X> {
+        X copy(X t) {
+            return t;
+        }
+    }
+
+    void testReciever() {
+        Number s = new Foo2<Number>().copy(0);
+    }
+
 }