changeset 50472:cece972575ac

8202372: Diagnostic with incorrect line info generated when compiling lambda expression Summary: Add tree position to speculative lambda tree Reviewed-by: vromero, jlahoda Contributed-by: bsrbnd@gmail.com
author mcimadamore
date Wed, 02 May 2018 15:29:55 +0100
parents 2143feab681a
children ff8dbb56740a 93cb8fb7a843
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java test/langtools/tools/javac/lambda/8202372/T8202372.java test/langtools/tools/javac/lambda/8202372/T8202372.out test/langtools/tools/javac/lvti/T8200199.java test/langtools/tools/javac/lvti/badTypeReference/BadTypeReference.java test/langtools/tools/javac/preview/classReaderTest/Client.java
diffstat 6 files changed, 57 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Wed May 02 13:44:49 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Wed May 02 15:29:55 2018 +0100
@@ -441,7 +441,7 @@
         } else {
             stats.add((JCBlock)that.body);
         }
-        JCBlock lambdaBlock = make.Block(0, stats.toList());
+        JCBlock lambdaBlock = make.at(that.pos).Block(0, stats.toList());
         Env<AttrContext> localEnv = attr.lambdaEnv(that, env);
         try {
             localEnv.info.returnResult = resultInfo;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/lambda/8202372/T8202372.java	Wed May 02 15:29:55 2018 +0100
@@ -0,0 +1,45 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8202372
+ * @summary Diagnostic with incorrect line info generated when compiling lambda expression
+ * @compile/fail/ref=T8202372.out -XDrawDiagnostics T8202372.java
+ */
+class T8202372 {
+
+    interface NonVoidFunc {
+        String m();
+    }
+
+    interface VoidFunc {
+        void m();
+    }
+
+    interface ParamFunc {
+        void m(String s);
+    }
+
+    public void addVoid(VoidFunc v) {}
+    public void addNonVoid(NonVoidFunc nv) {}
+    public void addParam(ParamFunc p) {}
+
+    void testVoid(T8202372 test) {
+        test.addVoid(() -> "");
+        test.addVoid(() -> { return ""; });
+        test.addVoid(() -> { });
+        test.addVoid(() -> { return; });
+    }
+
+    void testNonVoid(T8202372 test) {
+        test.addNonVoid(() -> "");
+        test.addNonVoid(() -> { return ""; });
+        test.addNonVoid(() -> { });
+        test.addNonVoid(() -> { return; });
+    }
+
+    void testParam(T8202372 test) {
+        test.addParam(() -> {});
+        test.addParam((String x) -> { });
+        test.addParam((String x1, String x2) -> { });
+        test.addParam((int x) -> { });
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/lambda/8202372/T8202372.out	Wed May 02 15:29:55 2018 +0100
@@ -0,0 +1,8 @@
+T8202372.java:26:13: compiler.err.cant.apply.symbol: kindname.method, addVoid, T8202372.VoidFunc, @22, kindname.class, T8202372, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.stat.expr.expected))
+T8202372.java:27:13: compiler.err.cant.apply.symbol: kindname.method, addVoid, T8202372.VoidFunc, @22, kindname.class, T8202372, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.unexpected.ret.val)))
+T8202372.java:35:13: compiler.err.cant.apply.symbol: kindname.method, addNonVoid, T8202372.NonVoidFunc, @25, kindname.class, T8202372, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.missing.ret.val: java.lang.String)))
+T8202372.java:36:13: compiler.err.cant.apply.symbol: kindname.method, addNonVoid, T8202372.NonVoidFunc, @25, kindname.class, T8202372, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.missing.ret.val)))
+T8202372.java:40:13: compiler.err.cant.apply.symbol: kindname.method, addParam, T8202372.ParamFunc, @23, kindname.class, T8202372, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.arg.types.in.lambda))
+T8202372.java:42:13: compiler.err.cant.apply.symbol: kindname.method, addParam, T8202372.ParamFunc, @23, kindname.class, T8202372, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.arg.types.in.lambda))
+T8202372.java:43:13: compiler.err.cant.apply.symbol: kindname.method, addParam, T8202372.ParamFunc, @23, kindname.class, T8202372, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.arg.types.in.lambda))
+7 errors
--- a/test/langtools/tools/javac/lvti/T8200199.java	Wed May 02 13:44:49 2018 +0200
+++ b/test/langtools/tools/javac/lvti/T8200199.java	Wed May 02 15:29:55 2018 +0100
@@ -24,7 +24,7 @@
  */
 
 /*
- * @test /nodynamioccopyright/
+ * @test /nodynamiccopyright/
  * @bug 8200199
  * @summary javac suggests to use var even when var is used
  * @compile/fail/ref=T8200199.out -Werror -XDfind=local -XDrawDiagnostics T8200199.java
--- a/test/langtools/tools/javac/lvti/badTypeReference/BadTypeReference.java	Wed May 02 13:44:49 2018 +0200
+++ b/test/langtools/tools/javac/lvti/badTypeReference/BadTypeReference.java	Wed May 02 15:29:55 2018 +0100
@@ -24,7 +24,7 @@
  */
 
 /*
- * @test /nodynamioccopyright/
+ * @test /nodynamiccopyright/
  * @bug 8177466
  * @summary Add compiler support for local variable type-inference
  * @compile -source 8 pkg/var.java
--- a/test/langtools/tools/javac/preview/classReaderTest/Client.java	Wed May 02 13:44:49 2018 +0200
+++ b/test/langtools/tools/javac/preview/classReaderTest/Client.java	Wed May 02 15:29:55 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * @test /nodynamioccopyright/
+ * @test /nodynamiccopyright/
  * @bug 8199194
  * @summary smoke test for --enabled-preview classreader support
  * @compile -XDforcePreview --enable-preview -source 11 Bar.java