changeset 1595:3a39d123d33a

8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply Summary: DiagnosticFilter used during speculative attribution is too broad Reviewed-by: jjg
author mcimadamore
date Thu, 21 Feb 2013 15:21:38 +0000
parents d686d8a7eb78
children f4fdd53f8b3e
files src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java test/tools/javac/lambda/speculative/MissingError.java test/tools/javac/lambda/speculative/MissingError.out
diffstat 4 files changed, 41 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Thu Feb 21 15:19:29 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Thu Feb 21 15:21:38 2013 +0000
@@ -276,14 +276,27 @@
      * disabled during speculative type-checking.
      */
     JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) {
-        JCTree newTree = new TreeCopier<Object>(make).copy(tree);
+        final JCTree newTree = new TreeCopier<Object>(make).copy(tree);
         Env<AttrContext> speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared()));
         speculativeEnv.info.scope.owner = env.info.scope.owner;
-        final JavaFileObject currentSource = log.currentSourceFile();
         Log.DeferredDiagnosticHandler deferredDiagnosticHandler =
                 new Log.DeferredDiagnosticHandler(log, new Filter<JCDiagnostic>() {
-            public boolean accepts(JCDiagnostic t) {
-                return t.getDiagnosticSource().getFile().equals(currentSource);
+            public boolean accepts(final JCDiagnostic d) {
+                class PosScanner extends TreeScanner {
+                    boolean found = false;
+
+                    @Override
+                    public void scan(JCTree tree) {
+                        if (tree != null &&
+                                tree.pos() == d.getDiagnosticPosition()) {
+                            found = true;
+                        }
+                        super.scan(tree);
+                    }
+                };
+                PosScanner posScanner = new PosScanner();
+                posScanner.scan(newTree);
+                return posScanner.found;
             }
         });
         try {
--- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Thu Feb 21 15:19:29 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Thu Feb 21 15:21:38 2013 +0000
@@ -484,6 +484,10 @@
         return getIntEndPosition();
     }
 
+    public DiagnosticPosition getDiagnosticPosition() {
+        return position;
+    }
+
     /**
      * Get the line number within the source referred to by this diagnostic.
      * @return  the line number within the source referred to by this diagnostic
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/speculative/MissingError.java	Thu Feb 21 15:21:38 2013 +0000
@@ -0,0 +1,17 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8008276
+ * @summary assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
+ * @compile/fail/ref=MissingError.out -XDrawDiagnostics MissingError.java
+ */
+class MissingError {
+    void test() {
+       mtest(new Bad(){ Integer i = ""; });
+    }
+
+    void mtest(Bad t){ }
+}
+
+class Bad {
+    String s = 1;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/speculative/MissingError.out	Thu Feb 21 15:21:38 2013 +0000
@@ -0,0 +1,3 @@
+MissingError.java:16:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.String)
+MissingError.java:9:37: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
+2 errors