Scala Programming Language
  1. Scala Programming Language
  2. SI-6124

Numeric literals should support "fill-in" underscores

    Details

    • Type: New Feature New Feature
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: Scala 2.10.0
    • Fix Version/s: None
    • Component/s: Parser Combinators
    • Labels:
    • Environment:

      Scala 2.10.x, 2.11.x

      Description

      src/compiler/scala/tools/nsc/javac/JavaScanners.scala does NOT support literals like 123_456_789.
      Since Java SE 7u4 (JDK 1.7 update 4), one can instantiate a java.lang.Long with java.lang.Long.valueOf (987_654_321).

      I have prepared a "fix" for this, see the attachment.

      At the same time, a similar patch adds support for underscores in numeric literals in Scala's own parser, namely src/compiler/scala/tools/nsc/ast/parser/Scanners.scala.

      There is also a simple test object which compiles and runs with the two Scanners patched with the Patch files.

      1. NumericLiteralWithUnderscores.scala
        0.2 kB
        Carlo Dapor
      2. Patch.JavaScanners
        0.7 kB
        Carlo Dapor
      3. Patch.Scanners
        0.7 kB
        Carlo Dapor

        Activity

        Hide
        Adriaan Moors added a comment -

        thanks for the patch! we should improve the Java scanner, but changing Scala syntax will require a SIP
        a pull request on github for the java-side of things much appreciated (please sign the Scala CLA first)

        Show
        Adriaan Moors added a comment - thanks for the patch! we should improve the Java scanner, but changing Scala syntax will require a SIP a pull request on github for the java-side of things much appreciated (please sign the Scala CLA first)
        Hide
        Adriaan Moors added a comment -

        Thanks for signing the CLA, Carlo! (this serves as proof you did – well, there's also the form we have on record in a file cabinet...)

        Show
        Adriaan Moors added a comment - Thanks for signing the CLA, Carlo! (this serves as proof you did – well, there's also the form we have on record in a file cabinet...)

          People

          • Assignee:
            Unassigned
            Reporter:
            Carlo Dapor
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:

              Development