From 8ef7080c083b8fead7588cff605134c25cb371ad Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sat, 30 Mar 2024 13:46:56 -0700 Subject: [PATCH] Don't process ignored escapes for raw --- .../tools/reflect/FastStringInterpolator.scala | 16 +++++----------- test/files/pos/t12976.scala | 6 ++++++ 2 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 test/files/pos/t12976.scala diff --git a/src/compiler/scala/tools/reflect/FastStringInterpolator.scala b/src/compiler/scala/tools/reflect/FastStringInterpolator.scala index 8d19adbd3fd0..da72c2cb3e33 100644 --- a/src/compiler/scala/tools/reflect/FastStringInterpolator.scala +++ b/src/compiler/scala/tools/reflect/FastStringInterpolator.scala @@ -36,9 +36,9 @@ 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 @@ -46,18 +46,12 @@ trait FastStringInterpolator extends FormatInterpolator { 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 diff --git a/test/files/pos/t12976.scala b/test/files/pos/t12976.scala new file mode 100644 index 000000000000..05d36de90a81 --- /dev/null +++ b/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) +}