Misleading compile error - regression

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Sun Apr 29 19:53:54 UTC 2018


Thanks - this seems good; I'll take a look for myself, and run some 
tests; if everything looks good I'll push.

Cheers
Maurizio


On 29/04/18 15:17, B. Blaser wrote:
> On 29 April 2018 at 13:55, B. Blaser <bsrbnd at gmail.com> wrote:
>> Hi,
>>
>> It looks like a missing 'make.at()' in
>> DeferredAttr::attribSpeculativeLambda, as next.
>> Tier1 seems OK.
>>
>> What do you think?
>>
>> Thanks,
>> Bernard
> ... with the test.
>
> Any comment is welcome,
> 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 15:53:09 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;
> diff -r 1871c5d07caf
> test/langtools/tools/javac/Diagnostics/8202372/T8202372.java
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/test/langtools/tools/javac/Diagnostics/8202372/T8202372.java
>   Sun Apr 29 15:53:09 2018 +0200
> @@ -0,0 +1,16 @@
> +/**
> + * @test
> + * @bug     8202372
> + * @summary Diagnostic with incorrect line info generated when
> compiling lambda expression.
> + * @compile/fail/ref=T8202372.out -XDrawDiagnostics -Xdiags:compact
> T8202372.java
> + */
> +public class T8202372 {
> +    public static interface I {
> +        public void m(String s);
> +    }
> +    public void add (I i) {}
> +    public static void main(String[] args) {
> +        T8202372 a = new T8202372();
> +        a.add(() -> {});
> +    }
> +}
> diff -r 1871c5d07caf test/langtools/tools/javac/Diagnostics/8202372/T8202372.out
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/test/langtools/tools/javac/Diagnostics/8202372/T8202372.out
>   Sun Apr 29 15:53:09 2018 +0200
> @@ -0,0 +1,3 @@
> +T8202372.java:14:15: compiler.err.prob.found.req:
> (compiler.misc.incompatible.arg.types.in.lambda)
> +- compiler.note.compressed.diags
> +1 error
>
>
>> 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