diff options
author | Simon Ochsenreither <simon@ochsenreither.de> | 2013-12-09 03:34:23 +0100 |
---|---|---|
committer | Simon Ochsenreither <simon@ochsenreither.de> | 2013-12-09 19:29:35 +0100 |
commit | 6688da4fb3e5bd886063568a3bcc57f2d184c703 (patch) | |
tree | d6c2abcf8b939e81f2652146a73d7af1f312114d /src | |
parent | d938f59e40e7ba97b199e5f70f252d191c19d93e (diff) | |
download | scala-6688da4fb3e5bd886063568a3bcc57f2d184c703.tar.gz scala-6688da4fb3e5bd886063568a3bcc57f2d184c703.tar.bz2 scala-6688da4fb3e5bd886063568a3bcc57f2d184c703.zip |
SI-7618 Remove octal number literals
This also fixes a spurious detection of octal literals in floating
point literals: Literals like 01.23 are neither deprecated nor planned
for removal.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index b12be1a056..65bb52159e 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -456,15 +456,6 @@ trait Scanners extends ScannersCommon { nextChar() base = 16 } else { - /* - * What should leading 0 be in the future? It is potentially dangerous - * to let it be base-10 because of history. Should it be an error? Is - * there a realistic situation where one would need it? - */ - if (isDigit(ch)) { - if (settings.future) syntaxError("Non-zero numbers may not have a leading zero.") - else deprecationWarning("Treating numbers with a leading zero as octal is deprecated.") - } base = 8 } getNumber() @@ -980,10 +971,15 @@ trait Scanners extends ScannersCommon { */ protected def getNumber() { val base1 = if (base < 10) 10 else base - // read 8,9's even if format is octal, produce a malformed number error afterwards. + // Read 8,9's even if format is octal, produce a malformed number error afterwards. + // At this point, we have already read the first digit, so to tell an innocent 0 apart + // from an octal literal 0123... (which we want to disallow), we check whether there + // are any additional digits coming after the first one we have already read. + var notSingleZero = false while (digit2int(ch, base1) >= 0) { putChar(ch) nextChar() + notSingleZero = true } token = INTLIT @@ -1000,6 +996,9 @@ trait Scanners extends ScannersCommon { if (base <= 10 && isEfd) getFraction() else { + // Checking for base == 8 is not enough, because base = 8 is set + // as soon as a 0 is read in `case '0'` of method fetchToken. + if (base == 8 && notSingleZero) syntaxError("Non-zero integral values may not have a leading zero.") setStrVal() if (isL) { nextChar() |