Skip to content

Commit 8fcbee5

Browse files
committed
Take advantage of the margin stripping interpolator.
Safer and shorter.
1 parent a0001fc commit 8fcbee5

File tree

9 files changed

+52
-55
lines changed

9 files changed

+52
-55
lines changed

src/compiler/scala/reflect/reify/Errors.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ trait Errors {
3333
}
3434

3535
def CannotConvertManifestToTagWithoutScalaReflect(tpe: Type, manifestInScope: Tree) = {
36-
val msg = s"""
37-
|to create a type tag here, it is necessary to interoperate with the manifest `$manifestInScope` in scope.
38-
|however manifest -> typetag conversion requires Scala reflection, which is not present on the classpath.
39-
|to proceed put scala-reflect.jar on your compilation classpath and recompile.""".trim.stripMargin
36+
val msg =
37+
sm"""to create a type tag here, it is necessary to interoperate with the manifest `$manifestInScope` in scope.
38+
|however manifest -> typetag conversion requires Scala reflection, which is not present on the classpath.
39+
|to proceed put scala-reflect.jar on your compilation classpath and recompile."""
4040
throw new ReificationException(defaultErrorPosition, msg)
4141
}
4242

src/compiler/scala/tools/nsc/transform/Erasure.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,19 @@ abstract class Erasure extends AddInterfaces
437437
noclash = false
438438
unit.error(
439439
if (member.owner == root) member.pos else root.pos,
440-
s"""bridge generated for member ${fulldef(member)}
441-
|which overrides ${fulldef(other)}
442-
|clashes with definition of $what;
443-
|both have erased type ${afterPostErasure(bridge.tpe)}""".stripMargin)
440+
sm"""bridge generated for member ${fulldef(member)}
441+
|which overrides ${fulldef(other)}
442+
|clashes with definition of $what;
443+
|both have erased type ${afterPostErasure(bridge.tpe)}""")
444444
}
445445
for (bc <- root.baseClasses) {
446446
if (settings.debug.value)
447447
afterPostErasure(println(
448-
s"""check bridge overrides in $bc
449-
${bc.info.nonPrivateDecl(bridge.name)}
450-
${site.memberType(bridge)}
451-
${site.memberType(bc.info.nonPrivateDecl(bridge.name) orElse IntClass)}
452-
${(bridge.matchingSymbol(bc, site))}""".stripMargin))
448+
sm"""check bridge overrides in $bc
449+
|${bc.info.nonPrivateDecl(bridge.name)}
450+
|${site.memberType(bridge)}
451+
|${site.memberType(bc.info.nonPrivateDecl(bridge.name) orElse IntClass)}
452+
|${(bridge.matchingSymbol(bc, site))}"""))
453453

454454
def overriddenBy(sym: Symbol) =
455455
sym.matchingSymbol(bc, site).alternatives filter (sym => !sym.isBridge)

src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ trait ContextErrors {
107107
s"$name extends Any, not AnyRef"
108108
)
109109
if (isPrimitiveValueType(found) || isTrivialTopType(tp)) "" else "\n" +
110-
s"""|Note that $what.
111-
|Such types can participate in value classes, but instances
112-
|cannot appear in singleton types or in reference comparisons.""".stripMargin
110+
sm"""|Note that $what.
111+
|Such types can participate in value classes, but instances
112+
|cannot appear in singleton types or in reference comparisons."""
113113
}
114114

115115
import ErrorUtils._
@@ -1128,9 +1128,9 @@ trait ContextErrors {
11281128
(isView: Boolean, pt: Type, tree: Tree)(implicit context0: Context) = {
11291129
if (!info1.tpe.isErroneous && !info2.tpe.isErroneous) {
11301130
def coreMsg =
1131-
s"""| $pre1 ${info1.sym.fullLocationString} of type ${info1.tpe}
1132-
| $pre2 ${info2.sym.fullLocationString} of type ${info2.tpe}
1133-
| $trailer""".stripMargin
1131+
sm"""| $pre1 ${info1.sym.fullLocationString} of type ${info1.tpe}
1132+
| $pre2 ${info2.sym.fullLocationString} of type ${info2.tpe}
1133+
| $trailer"""
11341134
def viewMsg = {
11351135
val found :: req :: _ = pt.typeArgs
11361136
def explanation = {
@@ -1141,19 +1141,19 @@ trait ContextErrors {
11411141
// involving Any, are further explained from foundReqMsg.
11421142
if (AnyRefClass.tpe <:< req) (
11431143
if (sym == AnyClass || sym == UnitClass) (
1144-
s"""|Note: ${sym.name} is not implicitly converted to AnyRef. You can safely
1145-
|pattern match `x: AnyRef` or cast `x.asInstanceOf[AnyRef]` to do so.""".stripMargin
1144+
sm"""|Note: ${sym.name} is not implicitly converted to AnyRef. You can safely
1145+
|pattern match `x: AnyRef` or cast `x.asInstanceOf[AnyRef]` to do so."""
11461146
)
11471147
else boxedClass get sym map (boxed =>
1148-
s"""|Note: an implicit exists from ${sym.fullName} => ${boxed.fullName}, but
1149-
|methods inherited from Object are rendered ambiguous. This is to avoid
1150-
|a blanket implicit which would convert any ${sym.fullName} to any AnyRef.
1151-
|You may wish to use a type ascription: `x: ${boxed.fullName}`.""".stripMargin
1148+
sm"""|Note: an implicit exists from ${sym.fullName} => ${boxed.fullName}, but
1149+
|methods inherited from Object are rendered ambiguous. This is to avoid
1150+
|a blanket implicit which would convert any ${sym.fullName} to any AnyRef.
1151+
|You may wish to use a type ascription: `x: ${boxed.fullName}`."""
11521152
) getOrElse ""
11531153
)
11541154
else
1155-
s"""|Note that implicit conversions are not applicable because they are ambiguous:
1156-
|${coreMsg}are possible conversion functions from $found to $req""".stripMargin
1155+
sm"""|Note that implicit conversions are not applicable because they are ambiguous:
1156+
|${coreMsg}are possible conversion functions from $found to $req"""
11571157
}
11581158
typeErrorMsg(found, req, infer.isPossiblyMissingArgs(found, req)) + (
11591159
if (explanation == "") "" else "\n" + explanation

src/compiler/scala/tools/nsc/typechecker/Implicits.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,17 +1306,17 @@ trait Implicits {
13061306
else {
13071307
if (ReflectRuntimeUniverse == NoSymbol) {
13081308
// todo. write a test for this
1309-
context.error(pos, s"""
1310-
|to create a manifest here, it is necessary to interoperate with the type tag `$tagInScope` in scope.
1311-
|however typetag -> manifest conversion requires Scala reflection, which is not present on the classpath.
1312-
|to proceed put scala-reflect.jar on your compilation classpath and recompile.""".trim.stripMargin)
1309+
context.error(pos,
1310+
sm"""to create a manifest here, it is necessary to interoperate with the type tag `$tagInScope` in scope.
1311+
|however typetag -> manifest conversion requires Scala reflection, which is not present on the classpath.
1312+
|to proceed put scala-reflect.jar on your compilation classpath and recompile.""")
13131313
return SearchFailure
13141314
}
13151315
if (resolveClassTag(pos, tp, allowMaterialization = true) == EmptyTree) {
1316-
context.error(pos, s"""
1317-
|to create a manifest here, it is necessary to interoperate with the type tag `$tagInScope` in scope.
1318-
|however typetag -> manifest conversion requires a class tag for the corresponding type to be present.
1319-
|to proceed add a class tag to the type `$tp` (e.g. by introducing a context bound) and recompile.""".trim.stripMargin)
1316+
context.error(pos,
1317+
sm"""to create a manifest here, it is necessary to interoperate with the type tag `$tagInScope` in scope.
1318+
|however typetag -> manifest conversion requires a class tag for the corresponding type to be present.
1319+
|to proceed add a class tag to the type `$tp` (e.g. by introducing a context bound) and recompile.""")
13201320
return SearchFailure
13211321
}
13221322
val cm = typed(Ident(ReflectRuntimeCurrentMirror))

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,8 +1379,8 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
13791379
private def checkCompileTimeOnly(sym: Symbol, pos: Position) = {
13801380
if (sym.isCompileTimeOnly) {
13811381
def defaultMsg =
1382-
s"""|Reference to ${sym.fullLocationString} should not have survived past type checking,
1383-
|it should have been processed and eliminated during expansion of an enclosing macro.""".stripMargin
1382+
sm"""Reference to ${sym.fullLocationString} should not have survived past type checking,
1383+
|it should have been processed and eliminated during expansion of an enclosing macro."""
13841384
// The getOrElse part should never happen, it's just here as a backstop.
13851385
unit.error(pos, sym.compileTimeOnlyMessage getOrElse defaultMsg)
13861386
}

src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,8 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
527527
}
528528
def isJavaProtected = host.isTrait && sym.isJavaDefined && {
529529
restrictionError(pos, unit,
530-
s"""|$clazz accesses protected $sym inside a concrete trait method.
531-
|Add an accessor in a class extending ${sym.enclClass} as a workaround.""".stripMargin
530+
sm"""$clazz accesses protected $sym inside a concrete trait method.
531+
|Add an accessor in a class extending ${sym.enclClass} as a workaround."""
532532
)
533533
true
534534
}

src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,9 @@ abstract class TreeCheckers extends Analyzer {
280280
if (sym.owner != currentOwner) {
281281
val expected = currentOwner.ownerChain find (x => cond(x)) getOrElse fail("DefTree can't find owner: ")
282282
if (sym.owner != expected)
283-
fail("""|
284-
| currentOwner chain: %s
285-
| symbol chain: %s""".stripMargin.format(
286-
currentOwner.ownerChain take 3 mkString " -> ",
287-
sym.ownerChain mkString " -> ")
283+
fail(sm"""|
284+
| currentOwner chain: ${currentOwner.ownerChain take 3 mkString " -> "}
285+
| symbol chain: ${sym.ownerChain mkString " -> "}"""
288286
)
289287
}
290288
}

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4863,12 +4863,12 @@ trait Typers extends Modes with Adaptations with Tags {
48634863
defSym = pre.member(defEntry.sym.name)
48644864
if (defSym ne defEntry.sym) {
48654865
qual = gen.mkAttributedQualifier(pre)
4866-
log(s"""
4866+
log(sm"""
48674867
| !!! Overloaded package object member resolved incorrectly.
48684868
| prefix: $pre
48694869
| Discarded: ${defEntry.sym.defString}
48704870
| Using: ${defSym.defString}
4871-
""".stripMargin)
4871+
""")
48724872
}
48734873
}
48744874
else

src/reflect/scala/reflect/runtime/JavaMirrors.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,10 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
129129
private def ErrorStaticModule(sym: Symbol) = throw new ScalaReflectionException(s"$sym is a static module, use reflectModule on a RuntimeMirror to obtain its ModuleMirror")
130130
private def ErrorNotMember(sym: Symbol, owner: Symbol) = throw new ScalaReflectionException(s"expected a member of $owner, you provided ${sym.kindString} ${sym.fullName}")
131131
private def ErrorNotField(sym: Symbol) = throw new ScalaReflectionException(s"expected a field or an accessor method symbol, you provided $sym")
132-
private def ErrorNonExistentField(sym: Symbol) = throw new ScalaReflectionException(s"""
133-
|Scala field ${sym.name} isn't represented as a Java field, neither it has a Java accessor method
134-
|note that private parameters of class constructors don't get mapped onto fields and/or accessors,
135-
|unless they are used outside of their declaring constructors.
136-
""".trim.stripMargin)
132+
private def ErrorNonExistentField(sym: Symbol) = throw new ScalaReflectionException(
133+
sm"""Scala field ${sym.name} isn't represented as a Java field, neither it has a Java accessor method
134+
|note that private parameters of class constructors don't get mapped onto fields and/or accessors,
135+
|unless they are used outside of their declaring constructors.""")
137136
private def ErrorSetImmutableField(sym: Symbol) = throw new ScalaReflectionException(s"cannot set an immutable field ${sym.name}")
138137
private def ErrorNotConstructor(sym: Symbol, owner: Symbol) = throw new ScalaReflectionException(s"expected a constructor of $owner, you provided $sym")
139138
private def ErrorFree(member: Symbol, freeType: Symbol) = throw new ScalaReflectionException(s"cannot reflect ${member.kindString} ${member.name}, because it's a member of a weak type ${freeType.name}")
@@ -541,8 +540,8 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
541540
val result = anns find (_.annotationType == annotClass)
542541
if (result.isEmpty && (anns exists (_.annotationType.getName == name)))
543542
throw new ClassNotFoundException(
544-
s"""Mirror classloader mismatch: $jclazz (loaded by ${ReflectionUtils.show(jclazz.getClassLoader)})
545-
|is unrelated to the mirror's classloader: (${ReflectionUtils.show(classLoader)})""".stripMargin)
543+
sm"""Mirror classloader mismatch: $jclazz (loaded by ${ReflectionUtils.show(jclazz.getClassLoader)})
544+
|is unrelated to the mirror's classloader: (${ReflectionUtils.show(classLoader)})""")
546545
result
547546
}
548547
def loadBytes[T: ClassTag](name: String): Option[T] =
@@ -955,8 +954,8 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
955954
javaTypeToValueClass(jclazz) orElse lookupClass
956955

957956
assert (cls.isType,
958-
s"""${if (cls == NoSymbol) "not a type: symbol" else "no symbol could be"}
959-
| loaded from $jclazz in $owner with name $simpleName and classloader $classLoader""".stripMargin)
957+
sm"""${if (cls == NoSymbol) "not a type: symbol" else "no symbol could be"}
958+
| loaded from $jclazz in $owner with name $simpleName and classloader $classLoader""")
960959

961960
cls.asClass
962961
}

0 commit comments

Comments
 (0)