[External] Re: BUG: local type inference -> symbol not found

Sietse Au sietse.au at booking.com
Tue Jun 9 12:49:55 UTC 2020


I've created a small project where the problem can be reproduced
consistently:
https://github.com/stau-booking/jdk11-reproduce-type-infer-bug

In this case the inferred type in the project is still `Anything`.

On Mon, Jun 8, 2020 at 10:55 PM Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:

> It would be interesting to know what is the inferred type for `someDao` -
> here's a dirty trick that you can use to let the compiler cough that up:
>
> final var someDao = ...
> String s = (String)someDao;
>
> This should hopefully cause a type mismatch and the compiler should tell
> you which type it tried to convert to String.
>
> I'm suspecting that this type might be a non-denotable type (e.g.
> anonymous class type, or intersection type) - which might be something that
> might trip javac up  when used as a method reference receivers?
>
> Maurizio
> On 08/06/2020 20:34, Sietse Au wrote:
>
>
> Hi,
>
> I've run into a compilation error on OpenJDK 11.06 (see attachment) where
> there is some interaction between local type inference and method
> reference.
>
> Haven't been able to create a clean project to reproduce the problem.
>
> Inside a larger code-base it is reproducible:
>
> final var someDao = ...
> someRequest.map(item -> SomeBuilder.builder()
>    ...
>    .build()
> ).forEach(someDao::create);
>
> the combination of the local type inference `final var` and the
> `someDao::create` method reference lead to the stacktrace in the attachment.
>
> When we rewrite the above to not use type inference and declare the type
> explicitly:
> final SomeDao someDao = ...
>
> OR
>
> rewrite the forEach not using the method reference:
> forEach(x -> someDao.create(x))
>
> the code compiles.
>
> As the stack trace itself was kind of unhelpful, hooking up to a debugger
> found that when the code hits `someDao::create` a SymbolNotFound error is
> thrown.
>
>
> Best regards,
> --
> Sietse Au
>
>

-- 
Sietse Au
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20200609/3e3e1579/attachment.htm>


More information about the compiler-dev mailing list