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
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Dec 03 16:31:23 2010 +0000
+++ b/langtools/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/langtools/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>(); }
+}