I'm trying to write a fast json parser for JVM in kotlin.
And I found this issue, I'm not sure this is a bug or any good reason behind this.
val x: Long = -9223372036854775808L // compile error
this is marked as a bug in kotlin KT-17172.
as you can see the stdlib using the code as below:
public const val MIN_VALUE: Long = -9223372036854775807L - 1L
are you remember unary operator -
in kotlin? if you divide the MIN_VALUE
into special parts you may see it clearly. for example:
val x: Long = -(9223372036854775808L);
// ^--- the value overflow since the MAX_VALUE is 9223372036854775807L