ceylon / ceylon.ast

Apache License 2.0
18 stars 3 forks source link

crash on large magnitude Integer literals #97

Closed jvasileff closed 8 years ago

jvasileff commented 8 years ago

General and specific issues:

  1. The spec does not limit the size of integer values; it is backend specific. For example, the Ceylon/JS Integer range extends well beyond that of Java's long.
  2. Even for the JVM (64-bit Integer), the full range is not currently supported by ceylon.ast; -9223372036854775808 appearing in code results in an assertion error.

IntegerLiteral.integer is of type Integer, but should be Whole or String. I suggest we go with String for now (or simply remove the integer property?), and use Whole in 1.3 if Whole goes cross-platform.

The problem with the 64-bit min-long value is that in the tree, it is represented as a negated positive value:

|  |  |  |  |  |  |  |  |  +  [Expression] (531:19-531:38) : Integer
|  |  |  |  |  |  |  |  |  |  + - [NegativeOp] (531:19-531:38) : Integer
|  |  |  |  |  |  |  |  |  |  |  + 9223372036854775808 [NaturalLiteral] (531:20-531:38) : Integer

and what would be:

NegationOperation(IntegerLiteral("9223372036854775808"))

and positive 9223372036854775808 is out of range on the JVM.

The stacktrace:

Exception in thread "main" ceylon.language.AssertionError "Assertion failed
    violated exists _integer = parseInteger(radix == 10 then text else text.rest, radix)"
    at ceylon.ast.core.IntegerLiteral.<init>(IntegerLiteral.ceylon:23)
    at ceylon.ast.redhat.integerLiteralToCeylon_.integerLiteralToCeylon(IntegerLiteral.ceylon:21)
    at ceylon.ast.redhat.literalToCeylon_.literalToCeylon(Literal.ceylon:35)
    at ceylon.ast.redhat.atomToCeylon_.atomToCeylon(Atom.ceylon:33)
    at ceylon.ast.redhat.primaryToCeylon_.primaryToCeylon(Primary.ceylon:38)
    at ceylon.ast.redhat.valueExpressionToCeylon_.valueExpressionToCeylon(ValueExpression.ceylon:24)
lucaswerkmeister commented 8 years ago

Done, IntegerLiteral.integer gone. See discussion in #98 and commit message.