From 36da62238be6efd92f2e59d9df6a4b29c4c7dae7 Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Sun, 24 Mar 2013 03:19:12 +0100 Subject: SI-7292 Deprecate octal escape literals --- src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 7 +++++++ test/files/neg/t7292-deprecation.check | 12 ++++++++++++ test/files/neg/t7292-deprecation.flags | 1 + test/files/neg/t7292-deprecation.scala | 5 +++++ test/files/neg/t7292-removal.check | 10 ++++++++++ test/files/neg/t7292-removal.flags | 1 + test/files/neg/t7292-removal.scala | 5 +++++ 7 files changed, 41 insertions(+) create mode 100644 test/files/neg/t7292-deprecation.check create mode 100644 test/files/neg/t7292-deprecation.flags create mode 100644 test/files/neg/t7292-deprecation.scala create mode 100644 test/files/neg/t7292-removal.check create mode 100644 test/files/neg/t7292-removal.flags create mode 100644 test/files/neg/t7292-removal.scala diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index eb31f7a66e..88ff21a90d 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -789,6 +789,7 @@ trait Scanners extends ScannersCommon { if (ch == '\\') { nextChar() if ('0' <= ch && ch <= '7') { + val start = charOffset - 2 val leadch: Char = ch var oct: Int = digit2int(ch, 8) nextChar() @@ -800,6 +801,12 @@ trait Scanners extends ScannersCommon { nextChar() } } + val alt = if (oct == LF) "\\n" else "\\u%04x" format oct + def msg(what: String) = s"Octal escape literals are $what, use $alt instead." + if (settings.future) + syntaxError(start, msg("unsupported")) + else + deprecationWarning(start, msg("deprecated")) putChar(oct.toChar) } else { ch match { diff --git a/test/files/neg/t7292-deprecation.check b/test/files/neg/t7292-deprecation.check new file mode 100644 index 0000000000..c7e6111962 --- /dev/null +++ b/test/files/neg/t7292-deprecation.check @@ -0,0 +1,12 @@ +t7292-deprecation.scala:2: warning: Octal escape literals are deprecated, use /u0000 instead. + val chr1 = '/0' + ^ +t7292-deprecation.scala:3: warning: Octal escape literals are deprecated, use /u0053 instead. + val str1 = "abc/123456" + ^ +t7292-deprecation.scala:4: warning: Octal escape literals are deprecated, use /n instead. + val lf = '/012' + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/test/files/neg/t7292-deprecation.flags b/test/files/neg/t7292-deprecation.flags new file mode 100644 index 0000000000..7de3c0f3ee --- /dev/null +++ b/test/files/neg/t7292-deprecation.flags @@ -0,0 +1 @@ +-Xfatal-warnings -deprecation diff --git a/test/files/neg/t7292-deprecation.scala b/test/files/neg/t7292-deprecation.scala new file mode 100644 index 0000000000..d857f0e1ec --- /dev/null +++ b/test/files/neg/t7292-deprecation.scala @@ -0,0 +1,5 @@ +object OctalEscapes { + val chr1 = '\0' + val str1 = "abc\123456" + val lf = '\012' +} diff --git a/test/files/neg/t7292-removal.check b/test/files/neg/t7292-removal.check new file mode 100644 index 0000000000..fffd0a1104 --- /dev/null +++ b/test/files/neg/t7292-removal.check @@ -0,0 +1,10 @@ +t7292-removal.scala:2: error: Octal escape literals are unsupported, use /u0000 instead. + val chr1 = '/0' + ^ +t7292-removal.scala:3: error: Octal escape literals are unsupported, use /u0053 instead. + val str1 = "abc/123456" + ^ +t7292-removal.scala:4: error: Octal escape literals are unsupported, use /n instead. + val lf = '/012' + ^ +three errors found diff --git a/test/files/neg/t7292-removal.flags b/test/files/neg/t7292-removal.flags new file mode 100644 index 0000000000..29f4ede37a --- /dev/null +++ b/test/files/neg/t7292-removal.flags @@ -0,0 +1 @@ +-Xfuture diff --git a/test/files/neg/t7292-removal.scala b/test/files/neg/t7292-removal.scala new file mode 100644 index 0000000000..d857f0e1ec --- /dev/null +++ b/test/files/neg/t7292-removal.scala @@ -0,0 +1,5 @@ +object OctalEscapes { + val chr1 = '\0' + val str1 = "abc\123456" + val lf = '\012' +} -- cgit v1.2.3