Skip to content

Commit 2ba76b1

Browse files
authored
Merge pull request #11140 from tanishiking/octal-escape-literal
Remove octal escape literals
2 parents dd74065 + 64aa7cf commit 2ba76b1

16 files changed

+30
-95
lines changed

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ object Scanners {
11461146
if (ch == '\\') {
11471147
nextChar()
11481148
if ('0' <= ch && ch <= '7') {
1149+
val start = charOffset - 2
11491150
val leadch: Char = ch
11501151
var oct: Int = digit2int(ch, 8)
11511152
nextChar()
@@ -1157,6 +1158,8 @@ object Scanners {
11571158
nextChar()
11581159
}
11591160
}
1161+
val alt = if oct == LF then raw"\n" else f"\u$oct%04x"
1162+
error(s"octal escape literals are unsupported: use $alt instead", start)
11601163
putChar(oct.toChar)
11611164
}
11621165
else if (ch == 'u' || ch == 'U') {

tests/neg-custom-args/typeclass-derivation2.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ object TypeLevel {
2626
val label: Array[Array[String]] =
2727
initLabels(0, 0, new mutable.ArrayBuffer[String], new mutable.ArrayBuffer[Array[String]])
2828

29-
private final val elemSeparator = '\000'
30-
private final val caseSeparator = '\001'
29+
private final val elemSeparator = '\u0000'
30+
private final val caseSeparator = '\u0001'
3131

3232
private def initLabels(start: Int, cur: Int,
3333
elems: mutable.ArrayBuffer[String],
@@ -135,7 +135,7 @@ object Lst {
135135
Shape.Case[Nil.type, EmptyTuple]
136136
)]
137137

138-
val genericClass = new GenericClass("Cons\000hd\000tl\001Nil")
138+
val genericClass = new GenericClass("Cons\u0000hd\u0000tl\u0001Nil")
139139
import genericClass.mirror
140140

141141
val NilMirror = mirror(1)
@@ -165,7 +165,7 @@ object Pair {
165165

166166
type Shape[T] = Shape.Case[Pair[T], (T, T)]
167167

168-
val genericClass = new GenericClass("Pair\000x\000y")
168+
val genericClass = new GenericClass("Pair\u0000x\u0000y")
169169
import genericClass.mirror
170170

171171
implicit def pairShape[T]: Shaped[Pair[T], Shape[T]] = new {
@@ -189,7 +189,7 @@ object Either {
189189
Shape.Case[Right[R], R *: EmptyTuple]
190190
)]
191191

192-
val genericClass = new GenericClass("Left\000x\001Right\000x")
192+
val genericClass = new GenericClass("Left\u0000x\u0001Right\u0000x")
193193
import genericClass.mirror
194194

195195
implicit def eitherShape[L, R]: Shaped[Either[L, R], Shape[L, R]] = new {

tests/neg/t7292-removal.check

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Error: tests/neg/t7292-removal.scala:2:14 ---------------------------------------------------------------------------
2+
2 | val chr1 = '\0' // error
3+
| ^
4+
| octal escape literals are unsupported: use \u0000 instead
5+
-- Error: tests/neg/t7292-removal.scala:3:17 ---------------------------------------------------------------------------
6+
3 | val str1 = "abc\123456" // error
7+
| ^
8+
| octal escape literals are unsupported: use \u0053 instead
9+
-- Error: tests/neg/t7292-removal.scala:4:12 ---------------------------------------------------------------------------
10+
4 | val lf = '\012' // error
11+
| ^
12+
| octal escape literals are unsupported: use \n instead

tests/neg/t7292-removal.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object OctalEscapes {
2+
val chr1 = '\0' // error
3+
val str1 = "abc\123456" // error
4+
val lf = '\012' // error
5+
}

tests/pending/run/t8266-octal-interp.check

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/pending/run/t8266-octal-interp.flags

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/pending/run/t8266-octal-interp.scala

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/run/richs.check

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
RichCharTest1:
33
true
44
true
5-
true
6-
true
75

86
RichIntTest:
97
10

tests/run/richs.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ trait RichTest {
1818
object RichCharTest1 extends RichTest {
1919
def run: Unit = {
2020
println("\n" + getObjectName + ":")
21-
println('\40'.isWhitespace)
22-
println('\011'.isWhitespace)
2321
println('1'.asDigit == 1)
2422
println('A'.asDigit == 10)
2523
}

tests/run/typeclass-derivation2a.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ object TypeLevel {
2525
def mirror(ordinal: Int): Mirror =
2626
mirror(ordinal, EmptyProduct)
2727

28-
private final val elemSeparator = '\000'
29-
private final val caseSeparator = '\001'
28+
private final val elemSeparator = '\u0000'
29+
private final val caseSeparator = '\u0001'
3030

3131
val label: Array[Array[String]] =
3232
initLabels(0, 0, new mutable.ArrayBuffer[String], new mutable.ArrayBuffer[Array[String]])
@@ -123,7 +123,7 @@ object Lst {
123123
// common compiler-generated infrastructure
124124
import TypeLevel._
125125

126-
val genericClass = new GenericClass("Cons\000hd\000tl\001Nil")
126+
val genericClass = new GenericClass("Cons\u0000hd\u0000tl\u0001Nil")
127127
import genericClass.mirror
128128

129129
private type ShapeOf[T] = Shape.Cases[(
@@ -158,7 +158,7 @@ object Pair {
158158
// common compiler-generated infrastructure
159159
import TypeLevel._
160160

161-
val genericClass = new GenericClass("Pair\000x\000y")
161+
val genericClass = new GenericClass("Pair\u0000x\u0000y")
162162
import genericClass.mirror
163163

164164
private type ShapeOf[T] = Shape.Case[Pair[T], (T, T)]
@@ -186,7 +186,7 @@ case class Right[R](x: R) extends Either[Nothing, R]
186186
object Either {
187187
import TypeLevel._
188188

189-
val genericClass = new GenericClass("Left\000x\001Right\000x")
189+
val genericClass = new GenericClass("Left\u0000x\u0001Right\u0000x")
190190
import genericClass.mirror
191191

192192
private type ShapeOf[L, R] = Shape.Cases[(

tests/untried/neg/t7292-deprecation.check

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/untried/neg/t7292-deprecation.flags

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/untried/neg/t7292-deprecation.scala

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/untried/neg/t7292-removal.check

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/untried/neg/t7292-removal.flags

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/untried/neg/t7292-removal.scala

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)