Misleading compile error - regression

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Apr 27 13:10:01 UTC 2018


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
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20180427/d8a372d0/attachment.html>


More information about the compiler-dev mailing list