Skip to content

Commit 35e57f1

Browse files
Fix #3655: Remove hl interpolator
1 parent b34ea5d commit 35e57f1

File tree

10 files changed

+337
-317
lines changed

10 files changed

+337
-317
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import collection.mutable.ListBuffer
1414
import reporting.diagnostic.messages._
1515
import reporting.trace
1616
import annotation.constructorOnly
17+
import printing.Formatting.hl
1718

1819
import scala.annotation.internal.sharable
1920

@@ -762,12 +763,12 @@ object desugar {
762763
def flagSourcePos(flag: FlagSet) = mods.mods.find(_.flags == flag).fold(mdef.sourcePos)(_.sourcePos)
763764

764765
if (mods.is(Abstract))
765-
ctx.error(hl"""$Abstract modifier cannot be used for objects""", flagSourcePos(Abstract))
766+
ctx.error(hl("Abstract") + " modifier cannot be used for objects", flagSourcePos(Abstract))
766767
if (mods.is(Sealed))
767-
ctx.error(hl"""$Sealed modifier is redundant for objects""", flagSourcePos(Sealed))
768+
ctx.error(hl("Sealed") + " modifier is redundant for objects", flagSourcePos(Sealed))
768769
// Maybe this should be an error; see https://github.com/scala/bug/issues/11094.
769770
if (mods.is(Final) && !mods.is(Synthetic))
770-
ctx.warning(hl"""$Final modifier is redundant for objects""", flagSourcePos(Final))
771+
ctx.warning(hl("Final") + " modifier is redundant for objects", flagSourcePos(Final))
771772

772773
if (mods is Package)
773774
PackageDef(Ident(moduleName), cpy.ModuleDef(mdef)(nme.PACKAGE, impl).withMods(mods &~ Package) :: Nil)

compiler/src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ object Decorators {
184184
}
185185

186186
implicit class StringInterpolators(val sc: StringContext) extends AnyVal {
187-
188187
/** General purpose string formatting */
189188
def i(args: Any*)(implicit ctx: Context): String =
190189
new StringFormatter(sc).assemble(args)
@@ -200,10 +199,6 @@ object Decorators {
200199
*/
201200
def ex(args: Any*)(implicit ctx: Context): String =
202201
explained(implicit ctx => em(args: _*))
203-
204-
/** Formatter that adds syntax highlighting to all interpolated values */
205-
def hl(args: Any*)(implicit ctx: Context): String =
206-
new SyntaxFormatter(sc).assemble(args).stripMargin
207202
}
208203

209204
implicit class ArrayInterpolator[T <: AnyRef](val arr: Array[T]) extends AnyVal {

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ object Formatting {
2323
* against accidentally treating an interpolated value as a margin.
2424
*/
2525
class StringFormatter(protected val sc: StringContext) {
26-
2726
protected def showArg(arg: Any)(implicit ctx: Context): String = arg match {
2827
case arg: Showable =>
2928
try arg.show
@@ -207,7 +206,7 @@ object Formatting {
207206
lazy val maxLen = parts.map(_._1.length).max
208207
parts.map {
209208
case (leader, trailer) =>
210-
val variable = hl"$leader"
209+
val variable = hl(leader)
211210
s"""$variable${" " * (maxLen - leader.length)} $trailer"""
212211
}
213212
}
@@ -277,4 +276,8 @@ object Formatting {
277276
case _ => (fnd, exp)
278277
}
279278
}
279+
280+
/** Explicit syntax highlighting */
281+
def hl(s: String)(implicit ctx: Context): String =
282+
SyntaxHighlighting.highlight(s)
280283
}

compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ trait MessageRendering {
134134
/** Explanation rendered under "Explanation" header */
135135
def explanation(m: Message)(implicit ctx: Context): String = {
136136
val sb = new StringBuilder(
137-
hl"""|
138-
|${Blue("Explanation")}
139-
|${Blue("===========")}"""
137+
s"""|
138+
|${Blue("Explanation").show}
139+
|${Blue("===========").show}""".stripMargin
140140
)
141141
sb.append(EOL).append(m.explanation)
142142
if (m.explanation.lastOption != Some(EOL)) sb.append(EOL)

0 commit comments

Comments
 (0)