BUG: local type inference -> symbol not found
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Jun 8 20:54:47 UTC 2020
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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20200608/243e9856/attachment.htm>
More information about the compiler-dev
mailing list