changeset 824:aa6605d883dc

7002837: Diamond: javac generates diamond inference errors when in 'finder' mode Summary: Javac should disable error messages when analyzing instance creation expression in 'diamond finder' mode Reviewed-by: jjg
author mcimadamore
date Fri, 03 Dec 2010 16:32:31 +0000
parents 9359f4222545
children 91b4f44c9742
files src/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/generics/diamond/7002837/T7002837.java
diffstat 2 files changed, 34 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Dec 03 16:31:23 2010 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Dec 03 16:32:31 2010 +0000
@@ -1587,13 +1587,26 @@
         } else if (allowDiamondFinder &&
                 clazztype.getTypeArguments().nonEmpty() &&
                 findDiamonds) {
-            Type inferred = attribDiamond(localEnv,
-                    tree,
-                    clazztype,
-                    mapping,
-                    argtypes,
-                    typeargtypes);
-            if (!inferred.isErroneous() &&
+            boolean prevDeferDiags = log.deferDiagnostics;
+            Queue<JCDiagnostic> prevDeferredDiags = log.deferredDiagnostics;
+            Type inferred = null;
+            try {
+                //disable diamond-related diagnostics
+                log.deferDiagnostics = true;
+                log.deferredDiagnostics = ListBuffer.lb();
+                inferred = attribDiamond(localEnv,
+                        tree,
+                        clazztype,
+                        mapping,
+                        argtypes,
+                        typeargtypes);
+            }
+            finally {
+                log.deferDiagnostics = prevDeferDiags;
+                log.deferredDiagnostics = prevDeferredDiags;
+            }
+            if (inferred != null &&
+                    !inferred.isErroneous() &&
                     inferred.tag == CLASS &&
                     types.isAssignable(inferred, pt.tag == NONE ? clazztype : pt, Warner.noWarnings) &&
                     chk.checkDiamond((ClassType)inferred).isEmpty()) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/diamond/7002837/T7002837.java	Fri Dec 03 16:32:31 2010 +0000
@@ -0,0 +1,14 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 7002837
+ *
+ * @summary  Diamond: javac generates diamond inference errors when in 'finder' mode
+ * @author mcimadamore
+ * @compile -Werror -XDfindDiamond T7002837.java
+ *
+ */
+
+class T7002837<X extends java.io.Serializable & Comparable<?>> {
+    T7002837() {}
+    { new T7002837<Integer>(); }
+}