Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't process ignored escapes for raw #10733

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/compiler/scala/tools/reflect/FastStringInterpolator.scala
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

//> using options -Xsource:3-cross

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