Permalink
Browse files

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.
  • Loading branch information...
1 parent d938f59 commit 6688da4fb3e5bd886063568a3bcc57f2d184c703 @soc soc committed Dec 9, 2013
@@ -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()
@@ -1,4 +1,4 @@
-warning: there were 18 deprecation warning(s); re-run with -deprecation for details
+warning: there were 5 deprecation warning(s); re-run with -deprecation for details
test '\u0024' == '$' was successful
test '\u005f' == '_' was successful
test 65.asInstanceOf[Char] == 'A' was successful
@@ -7,45 +7,34 @@ test "\0x61\0x62".trim() == "x61\0x62" was successful
test (65 : Byte) == 'A' was successful
-test 01 == 1 was successful
-test 010 == 8 was successful
test 0X01 == 1 was successful
test 0x01 == 1 was successful
test 0x10 == 16 was successful
test 0xa == 10 was successful
test 0x0a == 10 was successful
-test +01 == 1 was successful
-test +010 == 8 was successful
test +0x01 == 1 was successful
test +0x10 == 16 was successful
test +0xa == 10 was successful
test +0x0a == 10 was successful
-test -01 == -1 was successful
-test -010 == -8 was successful
test -0x01 == -1 was successful
test -0x10 == -16 was successful
test -0xa == -10 was successful
test -0x0a == -10 was successful
-test 017777777777 == 2147483647 was successful
-test 020000000000 == -2147483648 was successful
-test 037777777777 == -1 was successful
test 0x7fffffff == 2147483647 was successful
test 0x80000000 == -2147483648 was successful
test 0xffffffff == -1 was successful
test 1l == 1L was successful
test 1L == 1l was successful
test 1.asInstanceOf[Long] == 1l was successful
-test 0777777777777777777777L == 9223372036854775807L was successful
-test 01000000000000000000000L == -9223372036854775808L was successful
-test 01777777777777777777777L == -1L was successful
test 0x7fffffffffffffffL == 9223372036854775807L was successful
test 0x8000000000000000L == -9223372036854775808L was successful
test 0xffffffffffffffffL == -1L was successful
test 1e1f == 10.0f was successful
test .3f == 0.3f was successful
test 0f == 0.0f was successful
+test 01.23f == 1.23f was successful
test 3.14f == 3.14f was successful
test 6.022e23f == 6.022e23f was successful
test 09f == 9.0f was successful
@@ -56,6 +45,8 @@ test 1e1 == 10.0 was successful
test .3 == 0.3 was successful
test 0.0 == 0.0 was successful
test 0d == 0.0 was successful
+test 01.23 == 1.23 was successful
+test 01.23d == 1.23d was successful
test 3.14 == 3.14 was successful
test 1e-9d == 1.0e-9 was successful
test 1e137 == 1.0e137 was successful
@@ -47,32 +47,22 @@ object Test {
println
// int
- check_success("01 == 1", 01, 1)
- check_success("010 == 8", 010, 8)
check_success("0X01 == 1", 0X01, 1)
check_success("0x01 == 1", 0x01, 1)
check_success("0x10 == 16", 0x10, 16)
check_success("0xa == 10", 0xa, 10)
check_success("0x0a == 10", 0x0a, 10)
- check_success("+01 == 1", +01, 1)
- check_success("+010 == 8", +010, 8)
check_success("+0x01 == 1", +0x01, 1)
check_success("+0x10 == 16", +0x10, 16)
check_success("+0xa == 10", +0xa, 10)
check_success("+0x0a == 10", +0x0a, 10)
- check_success("-01 == -1", -01, -1)
- check_success("-010 == -8", -010, -8)
check_success("-0x01 == -1", -0x01, -1)
check_success("-0x10 == -16", -0x10, -16)
check_success("-0xa == -10", -0xa, -10)
check_success("-0x0a == -10", -0x0a, -10)
- check_success("017777777777 == 2147483647", 017777777777, 2147483647)
- check_success("020000000000 == -2147483648", 020000000000, -2147483648)
- check_success("037777777777 == -1", 037777777777, -1)
-
check_success("0x7fffffff == 2147483647", 0x7fffffff, 2147483647)
check_success("0x80000000 == -2147483648", 0x80000000, -2147483648)
check_success("0xffffffff == -1", 0xffffffff, -1)
@@ -84,13 +74,6 @@ object Test {
check_success("1L == 1l", 1L, 1l)
check_success("1.asInstanceOf[Long] == 1l", 1.asInstanceOf[Long], 1l)
- check_success("0777777777777777777777L == 9223372036854775807L",
- 0777777777777777777777L, 9223372036854775807L)
- check_success("01000000000000000000000L == -9223372036854775808L",
- 01000000000000000000000L, -9223372036854775808L)
- check_success("01777777777777777777777L == -1L",
- 01777777777777777777777L, -1L)
-
check_success("0x7fffffffffffffffL == 9223372036854775807L",
0x7fffffffffffffffL, 9223372036854775807L)
check_success("0x8000000000000000L == -9223372036854775808L",
@@ -105,9 +88,9 @@ object Test {
// float
check_success("1e1f == 10.0f", 1e1f, 10.0f)
- //check_success("2.f == 2.0f", 2.f, 2.0f)
check_success(".3f == 0.3f", .3f, 0.3f)
check_success("0f == 0.0f", 0f, 0.0f)
+ check_success("01.23f == 1.23f", 01.23f, 1.23f)
check_success("3.14f == 3.14f", 3.14f, 3.14f)
check_success("6.022e23f == 6.022e23f", 6.022e23f, 6.022e23f)
check_success("09f == 9.0f", 09f, 9.0f)
@@ -118,11 +101,11 @@ object Test {
// double
check_success("1e1 == 10.0", 1e1, 10.0)
- //check_success("2. == 2.0", 2., 2.0)
- //check_success("2.d == 2.0", 2.d, 2.0)
check_success(".3 == 0.3", .3, 0.3)
check_success("0.0 == 0.0", 0.0, 0.0)
check_success("0d == 0.0", 0d, 0.0)
+ check_success("01.23 == 1.23", 01.23, 1.23)
+ check_success("01.23d == 1.23d", 01.23d, 1.23d)
check_success("3.14 == 3.14", 3.14, 3.14)
check_success("1e-9d == 1.0e-9", 1e-9d, 1.0e-9)
check_success("1e137 == 1.0e137", 1e137, 1.0e137)

0 comments on commit 6688da4

Please sign in to comment.