Youssef Shoaib [MOD]
07/27/2024, 1:31 PMfun main() {
val x = 0.0
println(1.0) // 1
println(1.0.toString()) // 1
println("${1.0}") // 1.0
println(x) // 0
println(x.toString()) // 0
println("$x") // 0
}
Seems that "${1.0}"
gets converted at compile time to "1.0"
and not "1"
which is what the normal behaviour is on JSjw
07/27/2024, 2:16 PMYoussef Shoaib [MOD]
07/27/2024, 2:32 PM1
, I was relying on it to be 1.0.toString()
which it surprisingly isn't, and because when put in a variable I get the non-.0
result, I believe this is a weird constant folding bugjw
07/27/2024, 3:52 PMjw
07/27/2024, 3:53 PMYoussef Shoaib [MOD]
07/27/2024, 3:54 PMjw
07/27/2024, 3:58 PMjw
07/27/2024, 3:58 PMIvan Kylchik
07/29/2024, 9:46 AM// Will be evaluated on compile time
const val a = 1.0.toString()
fun main() {
println(a) // 1.0
// Will be evaluated on runtime
println(1.0.toString()) // 1
}
We tried to duplicate JS runtime behaviour, but there are problems. First, the specification is complicated. Second, the specification is not strict and the result can be different depending on JS engine (see KT-66922 for details). So for now we decided to live with different compile time and runtime result and come back to this problem later on (probably when we will start designing constant functions)