Thu, 21 Feb 2013 15:21:38 +0000
8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
Summary: DiagnosticFilter used during speculative attribution is too broad
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Thu Feb 21 15:19:29 2013 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Thu Feb 21 15:21:38 2013 +0000 1.3 @@ -276,14 +276,27 @@ 1.4 * disabled during speculative type-checking. 1.5 */ 1.6 JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) { 1.7 - JCTree newTree = new TreeCopier<Object>(make).copy(tree); 1.8 + final JCTree newTree = new TreeCopier<Object>(make).copy(tree); 1.9 Env<AttrContext> speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared())); 1.10 speculativeEnv.info.scope.owner = env.info.scope.owner; 1.11 - final JavaFileObject currentSource = log.currentSourceFile(); 1.12 Log.DeferredDiagnosticHandler deferredDiagnosticHandler = 1.13 new Log.DeferredDiagnosticHandler(log, new Filter<JCDiagnostic>() { 1.14 - public boolean accepts(JCDiagnostic t) { 1.15 - return t.getDiagnosticSource().getFile().equals(currentSource); 1.16 + public boolean accepts(final JCDiagnostic d) { 1.17 + class PosScanner extends TreeScanner { 1.18 + boolean found = false; 1.19 + 1.20 + @Override 1.21 + public void scan(JCTree tree) { 1.22 + if (tree != null && 1.23 + tree.pos() == d.getDiagnosticPosition()) { 1.24 + found = true; 1.25 + } 1.26 + super.scan(tree); 1.27 + } 1.28 + }; 1.29 + PosScanner posScanner = new PosScanner(); 1.30 + posScanner.scan(newTree); 1.31 + return posScanner.found; 1.32 } 1.33 }); 1.34 try {
2.1 --- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Thu Feb 21 15:19:29 2013 +0000 2.2 +++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Thu Feb 21 15:21:38 2013 +0000 2.3 @@ -484,6 +484,10 @@ 2.4 return getIntEndPosition(); 2.5 } 2.6 2.7 + public DiagnosticPosition getDiagnosticPosition() { 2.8 + return position; 2.9 + } 2.10 + 2.11 /** 2.12 * Get the line number within the source referred to by this diagnostic. 2.13 * @return the line number within the source referred to by this diagnostic
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/lambda/speculative/MissingError.java Thu Feb 21 15:21:38 2013 +0000 3.3 @@ -0,0 +1,17 @@ 3.4 +/* 3.5 + * @test /nodynamiccopyright/ 3.6 + * @bug 8008276 3.7 + * @summary assertion error in com.sun.tools.javac.comp.TransTypes.visitApply 3.8 + * @compile/fail/ref=MissingError.out -XDrawDiagnostics MissingError.java 3.9 + */ 3.10 +class MissingError { 3.11 + void test() { 3.12 + mtest(new Bad(){ Integer i = ""; }); 3.13 + } 3.14 + 3.15 + void mtest(Bad t){ } 3.16 +} 3.17 + 3.18 +class Bad { 3.19 + String s = 1; 3.20 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/lambda/speculative/MissingError.out Thu Feb 21 15:21:38 2013 +0000 4.3 @@ -0,0 +1,3 @@ 4.4 +MissingError.java:16:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.String) 4.5 +MissingError.java:9:37: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer) 4.6 +2 errors