From 64aa7cfb0a0a245261c490e268052880a07f5c00 Mon Sep 17 00:00:00 2001 From: tanishiking Date: Sun, 17 Jan 2021 23:10:32 +0900 Subject: [PATCH] Remove octal escape literals Closes https://github.com/lampepfl/dotty/issues/10895 Ref https://github.com/scala/scala/pull/6324 This PR removes octal escape in String literals, which was deprecated and removed in scala 2. --- .../dotty/tools/dotc/parsing/Scanners.scala | 3 ++ .../typeclass-derivation2.scala | 10 +++---- tests/neg/t7292-removal.check | 12 ++++++++ tests/neg/t7292-removal.scala | 5 ++++ tests/pending/run/t8266-octal-interp.check | 30 ------------------- tests/pending/run/t8266-octal-interp.flags | 1 - tests/pending/run/t8266-octal-interp.scala | 16 ---------- tests/run/richs.check | 2 -- tests/run/richs.scala | 2 -- tests/run/typeclass-derivation2a.scala | 10 +++---- tests/untried/neg/t7292-deprecation.check | 12 -------- tests/untried/neg/t7292-deprecation.flags | 1 - tests/untried/neg/t7292-deprecation.scala | 5 ---- tests/untried/neg/t7292-removal.check | 10 ------- tests/untried/neg/t7292-removal.flags | 1 - tests/untried/neg/t7292-removal.scala | 5 ---- 16 files changed, 30 insertions(+), 95 deletions(-) create mode 100644 tests/neg/t7292-removal.check create mode 100644 tests/neg/t7292-removal.scala delete mode 100644 tests/pending/run/t8266-octal-interp.check delete mode 100644 tests/pending/run/t8266-octal-interp.flags delete mode 100644 tests/pending/run/t8266-octal-interp.scala delete mode 100644 tests/untried/neg/t7292-deprecation.check delete mode 100644 tests/untried/neg/t7292-deprecation.flags delete mode 100644 tests/untried/neg/t7292-deprecation.scala delete mode 100644 tests/untried/neg/t7292-removal.check delete mode 100644 tests/untried/neg/t7292-removal.flags delete mode 100644 tests/untried/neg/t7292-removal.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index aae4aab4e588..2c9c0cabf1e9 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -1146,6 +1146,7 @@ object Scanners { if (ch == '\\') { nextChar() if ('0' <= ch && ch <= '7') { + val start = charOffset - 2 val leadch: Char = ch var oct: Int = digit2int(ch, 8) nextChar() @@ -1157,6 +1158,8 @@ object Scanners { nextChar() } } + val alt = if oct == LF then raw"\n" else f"\u$oct%04x" + error(s"octal escape literals are unsupported: use $alt instead", start) putChar(oct.toChar) } else if (ch == 'u' || ch == 'U') { diff --git a/tests/neg-custom-args/typeclass-derivation2.scala b/tests/neg-custom-args/typeclass-derivation2.scala index b1a32fe65343..525d3ea040da 100644 --- a/tests/neg-custom-args/typeclass-derivation2.scala +++ b/tests/neg-custom-args/typeclass-derivation2.scala @@ -26,8 +26,8 @@ object TypeLevel { val label: Array[Array[String]] = initLabels(0, 0, new mutable.ArrayBuffer[String], new mutable.ArrayBuffer[Array[String]]) - private final val elemSeparator = '\000' - private final val caseSeparator = '\001' + private final val elemSeparator = '\u0000' + private final val caseSeparator = '\u0001' private def initLabels(start: Int, cur: Int, elems: mutable.ArrayBuffer[String], @@ -135,7 +135,7 @@ object Lst { Shape.Case[Nil.type, EmptyTuple] )] - val genericClass = new GenericClass("Cons\000hd\000tl\001Nil") + val genericClass = new GenericClass("Cons\u0000hd\u0000tl\u0001Nil") import genericClass.mirror val NilMirror = mirror(1) @@ -165,7 +165,7 @@ object Pair { type Shape[T] = Shape.Case[Pair[T], (T, T)] - val genericClass = new GenericClass("Pair\000x\000y") + val genericClass = new GenericClass("Pair\u0000x\u0000y") import genericClass.mirror implicit def pairShape[T]: Shaped[Pair[T], Shape[T]] = new { @@ -189,7 +189,7 @@ object Either { Shape.Case[Right[R], R *: EmptyTuple] )] - val genericClass = new GenericClass("Left\000x\001Right\000x") + val genericClass = new GenericClass("Left\u0000x\u0001Right\u0000x") import genericClass.mirror implicit def eitherShape[L, R]: Shaped[Either[L, R], Shape[L, R]] = new { diff --git a/tests/neg/t7292-removal.check b/tests/neg/t7292-removal.check new file mode 100644 index 000000000000..9a0df3d9eebc --- /dev/null +++ b/tests/neg/t7292-removal.check @@ -0,0 +1,12 @@ +-- Error: tests/neg/t7292-removal.scala:2:14 --------------------------------------------------------------------------- +2 | val chr1 = '\0' // error + | ^ + | octal escape literals are unsupported: use \u0000 instead +-- Error: tests/neg/t7292-removal.scala:3:17 --------------------------------------------------------------------------- +3 | val str1 = "abc\123456" // error + | ^ + | octal escape literals are unsupported: use \u0053 instead +-- Error: tests/neg/t7292-removal.scala:4:12 --------------------------------------------------------------------------- +4 | val lf = '\012' // error + | ^ + | octal escape literals are unsupported: use \n instead diff --git a/tests/neg/t7292-removal.scala b/tests/neg/t7292-removal.scala new file mode 100644 index 000000000000..5da53aa18bcb --- /dev/null +++ b/tests/neg/t7292-removal.scala @@ -0,0 +1,5 @@ +object OctalEscapes { + val chr1 = '\0' // error + val str1 = "abc\123456" // error + val lf = '\012' // error +} diff --git a/tests/pending/run/t8266-octal-interp.check b/tests/pending/run/t8266-octal-interp.check deleted file mode 100644 index 66ecafddc2ac..000000000000 --- a/tests/pending/run/t8266-octal-interp.check +++ /dev/null @@ -1,30 +0,0 @@ -t8266-octal-interp.scala:4: warning: Octal escape literals are deprecated, use \b instead. - f"a\10c", - ^ -t8266-octal-interp.scala:5: warning: Octal escape literals are deprecated, use \t instead. - f"a\11c", - ^ -t8266-octal-interp.scala:6: warning: Octal escape literals are deprecated, use \n instead. - f"a\12c", - ^ -t8266-octal-interp.scala:7: warning: Octal escape literals are deprecated, use \r instead. - f"a\15c", - ^ -t8266-octal-interp.scala:8: warning: Octal escape literals are deprecated, use ${'"'} or a triple-quoted literal """with embedded " or \u0022""" instead. - f"a\42c", - ^ -t8266-octal-interp.scala:9: warning: Octal escape literals are deprecated, use \\ instead. - f"a\134c", - ^ -t8266-octal-interp.scala:10: warning: Octal escape literals are deprecated, use \u0069 instead. - f"a\15151515c" - ^ -ac -a c -a -c -a -c -a"c -a\c -ai51515c diff --git a/tests/pending/run/t8266-octal-interp.flags b/tests/pending/run/t8266-octal-interp.flags deleted file mode 100644 index dcc59ebe32ef..000000000000 --- a/tests/pending/run/t8266-octal-interp.flags +++ /dev/null @@ -1 +0,0 @@ --deprecation diff --git a/tests/pending/run/t8266-octal-interp.scala b/tests/pending/run/t8266-octal-interp.scala deleted file mode 100644 index f85ae0367dbc..000000000000 --- a/tests/pending/run/t8266-octal-interp.scala +++ /dev/null @@ -1,16 +0,0 @@ - -trait X { - def f = Seq( - f"a\10c", - f"a\11c", - f"a\12c", - f"a\15c", - f"a\42c", - f"a\134c", - f"a\15151515c" - ) -} - -object Test extends App with X { - f foreach println -} diff --git a/tests/run/richs.check b/tests/run/richs.check index a970a814b189..48812eb28939 100644 --- a/tests/run/richs.check +++ b/tests/run/richs.check @@ -2,8 +2,6 @@ RichCharTest1: true true -true -true RichIntTest: 10 diff --git a/tests/run/richs.scala b/tests/run/richs.scala index 59f833245509..e5c1d07880dc 100644 --- a/tests/run/richs.scala +++ b/tests/run/richs.scala @@ -18,8 +18,6 @@ trait RichTest { object RichCharTest1 extends RichTest { def run: Unit = { println("\n" + getObjectName + ":") - println('\40'.isWhitespace) - println('\011'.isWhitespace) println('1'.asDigit == 1) println('A'.asDigit == 10) } diff --git a/tests/run/typeclass-derivation2a.scala b/tests/run/typeclass-derivation2a.scala index 4b9447b5591a..68d7cf4f13d0 100644 --- a/tests/run/typeclass-derivation2a.scala +++ b/tests/run/typeclass-derivation2a.scala @@ -25,8 +25,8 @@ object TypeLevel { def mirror(ordinal: Int): Mirror = mirror(ordinal, EmptyProduct) - private final val elemSeparator = '\000' - private final val caseSeparator = '\001' + private final val elemSeparator = '\u0000' + private final val caseSeparator = '\u0001' val label: Array[Array[String]] = initLabels(0, 0, new mutable.ArrayBuffer[String], new mutable.ArrayBuffer[Array[String]]) @@ -123,7 +123,7 @@ object Lst { // common compiler-generated infrastructure import TypeLevel._ - val genericClass = new GenericClass("Cons\000hd\000tl\001Nil") + val genericClass = new GenericClass("Cons\u0000hd\u0000tl\u0001Nil") import genericClass.mirror private type ShapeOf[T] = Shape.Cases[( @@ -158,7 +158,7 @@ object Pair { // common compiler-generated infrastructure import TypeLevel._ - val genericClass = new GenericClass("Pair\000x\000y") + val genericClass = new GenericClass("Pair\u0000x\u0000y") import genericClass.mirror private type ShapeOf[T] = Shape.Case[Pair[T], (T, T)] @@ -186,7 +186,7 @@ case class Right[R](x: R) extends Either[Nothing, R] object Either { import TypeLevel._ - val genericClass = new GenericClass("Left\000x\001Right\000x") + val genericClass = new GenericClass("Left\u0000x\u0001Right\u0000x") import genericClass.mirror private type ShapeOf[L, R] = Shape.Cases[( diff --git a/tests/untried/neg/t7292-deprecation.check b/tests/untried/neg/t7292-deprecation.check deleted file mode 100644 index 17f010dfdf33..000000000000 --- a/tests/untried/neg/t7292-deprecation.check +++ /dev/null @@ -1,12 +0,0 @@ -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/tests/untried/neg/t7292-deprecation.flags b/tests/untried/neg/t7292-deprecation.flags deleted file mode 100644 index 7de3c0f3eea0..000000000000 --- a/tests/untried/neg/t7292-deprecation.flags +++ /dev/null @@ -1 +0,0 @@ --Xfatal-warnings -deprecation diff --git a/tests/untried/neg/t7292-deprecation.scala b/tests/untried/neg/t7292-deprecation.scala deleted file mode 100644 index d857f0e1ecea..000000000000 --- a/tests/untried/neg/t7292-deprecation.scala +++ /dev/null @@ -1,5 +0,0 @@ -object OctalEscapes { - val chr1 = '\0' - val str1 = "abc\123456" - val lf = '\012' -} diff --git a/tests/untried/neg/t7292-removal.check b/tests/untried/neg/t7292-removal.check deleted file mode 100644 index 1cd59b099290..000000000000 --- a/tests/untried/neg/t7292-removal.check +++ /dev/null @@ -1,10 +0,0 @@ -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/tests/untried/neg/t7292-removal.flags b/tests/untried/neg/t7292-removal.flags deleted file mode 100644 index 29f4ede37ab4..000000000000 --- a/tests/untried/neg/t7292-removal.flags +++ /dev/null @@ -1 +0,0 @@ --Xfuture diff --git a/tests/untried/neg/t7292-removal.scala b/tests/untried/neg/t7292-removal.scala deleted file mode 100644 index d857f0e1ecea..000000000000 --- a/tests/untried/neg/t7292-removal.scala +++ /dev/null @@ -1,5 +0,0 @@ -object OctalEscapes { - val chr1 = '\0' - val str1 = "abc\123456" - val lf = '\012' -}