https://kotlinlang.org logo
#announcements
Title
# announcements
g

gregopet

07/31/2017, 8:26 AM
It looks like a compiler bug to me, but I'm no expert - I'll reproduce this in a simple self-contained case and upload it somewhere
k

karelpeeters

07/31/2017, 8:28 AM
No that's a problem with the method you're calling, it promises it cab return whatever type you want.
The compiler picks the most specific type it can, and at runtime it shows that the method lied about it's return type.
g

gregopet

07/31/2017, 8:39 AM
Hmmm, I see, interesting... thank you!
k

karelpeeters

07/31/2017, 9:10 AM
And that method probably does that to make it easier for the user, so you don't need to cast everything, it does it for you internally.
g

gregopet

07/31/2017, 9:18 AM
Yes, it does, my fault for not using it as intended I suppose; still at this level I would rather not have separate methods for lists and objects just yet
My line of reasoning went that since the method was returning
Any
the compiler should use this information, but of course the compiler first processes the
if
node and tries to be as strongly typed as possible
I mean, I can imagine its current behavior making code less verbose, or that it tries to be as strongly typed as possible, it just surprised me 🙂
..the original code was written a few months ago and I forgot about the exact parser syntax, then today I did the mistake of applying a simple micro optimization 😛
thanks again!
☺️ 1