Skip to content

Commit

Permalink
Merge pull request #10733 from som-snytt/issue/12976-raw-u
Browse files Browse the repository at this point in the history
Don't process ignored escapes for raw
  • Loading branch information
SethTisue committed Apr 8, 2024
2 parents 25818df + 8ef7080 commit 270f4bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/compiler/scala/tools/reflect/FastStringInterpolator.scala
Expand Up @@ -36,28 +36,22 @@ trait FastStringInterpolator extends FormatInterpolator {
try
parts.mapConserve {
case lit @ Literal(Constant(stringVal: String)) =>
def asRaw = {
def asRaw = if (currentRun.sourceFeatures.unicodeEscapesRaw) stringVal else {
val processed = StringContext.processUnicode(stringVal)
if (processed != stringVal) {
if (processed == stringVal) stringVal else {
val pos = {
val diffindex = processed.zip(stringVal).zipWithIndex.collectFirst {
case ((p, o), i) if p != o => i
}.getOrElse(processed.length - 1)
lit.pos.withShift(diffindex)
}
def msg(fate: String) = s"Unicode escapes in raw interpolations are $fate; use literal characters instead"
if (currentRun.sourceFeatures.unicodeEscapesRaw)
stringVal
else if (currentRun.isScala3) {
if (currentRun.isScala3)
runReporting.warning(pos, msg("ignored in Scala 3 (or with -Xsource-features:unicode-escapes-raw)"), Scala3Migration, c.internal.enclosingOwner)
processed
}
else {
else
runReporting.deprecationWarning(pos, msg("deprecated"), "2.13.2", "", "")
processed
}
processed
}
else stringVal
}
val value =
if (isRaw) asRaw
Expand Down
6 changes: 6 additions & 0 deletions test/files/pos/t12976.scala
@@ -0,0 +1,6 @@

//> using options -Xsource:3-cross

trait T {
def f(c: Char) = raw"\u%04X".format(c.toInt)
}

0 comments on commit 270f4bf

Please sign in to comment.