Closed rpuxa closed 4 years ago
I ran this code in kotlin playground and it returned false, but in IntelliJ IDEA it returns true! WTF?
Playground uses 1.3.41 or 1.3.50, what's your project using? It could also be a NewInference bug?
I've tried on 1.3.50 and 1.3.60. Both versions print true.
So we need an option "it depends" 😮.
I also get true
when pasting the two lines into kotlinc
1.3.50
By the way, one of the things I discovered - if you open Tools >> Kotlin >> Show Kotlin bytecode, it shows wrong bytecode. To figure out how code works i had to use external bytecode viewer.
And if you change platform to JS on playground it becomes to print true (╯°□°)╯︵ ┻━┻
(╯°□°)╯︵ ┻━┻
I think you just proved that it's a good puzzler!
I put this into a kts file and it returns false, but yes, pasting to kotlinc returns true. Probably would need to find somebody to explain this @ KotlinConf :-)
a) true b) false c) number !is Double d) None of the above
Correct answer: a. Compiler ignores smart cast to Double and compares numbers like Objects, i.e. using equals() method. And equals() method returns true if it compares two NaNs.