janino-compiler / janino

Janino is a super-small, super-fast Java™ compiler.
http://janino-compiler.github.io/janino
Other
1.25k stars 208 forks source link

Ternary expression resolves to strange supertype #85

Closed gabor-farkas closed 5 years ago

gabor-farkas commented 5 years ago

Hello,

Evaluating:

List list = true ? new ArrayList() : Arrays.asList(new String [] {});

Doesn't compile, with the error message: Assignment conversion not possible from type "java.util.Collection" to type "java.util.List"

I prepared this in the form of a unit test: https://github.com/gabor-farkas/janino-ternary-expression It works with 3.0.11 but fails with 3.0.12

aunkrig commented 5 years ago

Thank you for your very precise bug report!

Reproduced, diagnosed and fixed.

The bug was introduced in the context of

The ?: operator no longer issues an error when the MHS is not assignable from the RHS and vice versa; instead, the expression type is the "common base type" of the MHS and RHS.

Please re-test!

gabor-farkas commented 5 years ago

Thanks for the quick fix! I tested and I can confirm it works fine now!

aunkrig commented 5 years ago

Great! Do you want me to create a new Janino release?

gabor-farkas commented 5 years ago

If it's not planned otherwise to happen soon, then yes, it would be helpful, thanks!

aunkrig commented 5 years ago

FYI: I just released version 3.0.13, so the fix is now available in an official release.

gabor-farkas commented 5 years ago

Thanks! I'll give it a try.