Misleading compile error - regression

B. Blaser bsrbnd at gmail.com
Sun Apr 29 11:55:06 UTC 2018


Hi,

It looks like a missing 'make.at()' in
DeferredAttr::attribSpeculativeLambda, as next.
Tier1 seems OK.

What do you think?

Thanks,
Bernard

diff -r 1871c5d07caf
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
Fri Apr 27 15:55:29 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
Sun Apr 29 13:34:13 2018 +0200
@@ -441,7 +441,7 @@
         } else {
             stats.add((JCBlock)that.body);
         }
-        JCBlock lambdaBlock = make.Block(0, stats.toList());
+        JCBlock lambdaBlock = make.at(that).Block(0, stats.toList());
         Env<AttrContext> localEnv = attr.lambdaEnv(that, env);
         try {
             localEnv.info.returnResult = resultInfo;


On 27 April 2018 at 15:10, Maurizio Cimadamore
<maurizio.cimadamore at oracle.com> wrote:
> Thanks for the report - I have not seen this before; I filed this:
>
> https://bugs.openjdk.java.net/browse/JDK-8202372
>
> I've noted that if the lambda expression is changed to contain e.g. too many
> args, the diag position issue is fixed.
>
> Maurizio
>
>
> On 27/04/18 14:01, Sven Reimers wrote:
>
> Hi all,
>
> using a compiler from 9, 10, 11 the following code
>
> package issue;
> public class A {
>
>     public static interface I {
>         public void m(String s);
>     }
>
>     public void add (I i) {}
>
>     public static void main(String[] args) {
>         A a = new A();
>         a.add(() -> {});
>     }
> }
>
> results in
>
> ... issue/A.java:2: error: incompatible types: incompatible parameter types
> in lambda expression
> public class A {
> Note: Some messages have been simplified; recompile with -Xdiags:verbose to
> get full output
> 1 error
>
> With -Xdiags:verbose the message is correct
>
> ... issue/A.java:12: error: method add in class A cannot be applied to given
> types;
>         a.add(() -> {});
>   required: I
>   found: ()->{ }
>   reason: argument mismatch; incompatible parameter types in lambda
> expression
> 1 error
>
> -> Look at the difference in the line number.
>
> Using JDK 8 everything works as expected (correct line number without
> -Xdiags:verbose).
>
> I assume this is not the desired behavior.
>
> Is this already known? Any issue in JBS already?
>
> Thanks
>
> Sven
>
> --
> Sven Reimers
>
> * Senior Expert Software Architect
> * Java Champion
>
>


More information about the compiler-dev mailing list