diff --git a/src/share/classes/com/sun/tools/javac/comp/Attr.java b/src/share/classes/com/sun/tools/javac/comp/Attr.java index 4ff6f178f8ebbfabc26bec99f31a53bb423d57ac..335c3249267032232ccb7c5d24dd99e7cb47f661 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -2195,7 +2195,9 @@ public class Attr extends JCTree.Visitor { 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"; diff --git a/test/tools/javac/generics/diamond/6939780/T6939780.java b/test/tools/javac/generics/diamond/6939780/T6939780.java index 57bbe4a92b3c6c97b57cf2984c74f2ffae00d6a7..d3f41e44fb7862c87f8180838d3b71d4e333fd09 100644 --- a/test/tools/javac/generics/diamond/6939780/T6939780.java +++ b/test/tools/javac/generics/diamond/6939780/T6939780.java @@ -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 @@ class T6939780 { void gw(Foo fw) { } void gn(Foo fn) { } + + static class Foo2 { + X copy(X t) { + return t; + } + } + + void testReciever() { + Number s = new Foo2().copy(0); + } + }