2

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
damphat
  • 18,246
  • 8
  • 45
  • 59
  • 2
    And `-9223372036854775807L` is accepted, interesting... Btw, it would be helpful if the exact message was provided. – zerkms Jun 25 '17 at 05:13

1 Answers1

4

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
holi-java
  • 29,655
  • 7
  • 72
  • 83