Skip to content

Commit fe7b943

Browse files
replace i"..." by d"..." if string might go into a
Diagnostic and might be nonsensical
1 parent 03935c9 commit fe7b943

File tree

8 files changed

+58
-58
lines changed

8 files changed

+58
-58
lines changed

src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ trait Applications extends Compatibility { self: Typer =>
647647
maximizeType(unapplyArgType) match {
648648
case Some(tvar) =>
649649
def msg =
650-
i"""There is no best instantiation of pattern type $unapplyArgType
650+
d"""There is no best instantiation of pattern type $unapplyArgType
651651
|that makes it a subtype of selector type $pt.
652652
|Non-variant type variable ${tvar.origin} cannot be uniquely instantiated.""".stripMargin
653653
if (fromScala2x) {
@@ -671,7 +671,7 @@ trait Applications extends Compatibility { self: Typer =>
671671
unapp.println("Neither sub nor super")
672672
unapp.println(TypeComparer.explained(implicit ctx => unapplyArgType <:< wpt))
673673
errorType(
674-
i"Pattern type $unapplyArgType is neither a subtype nor a supertype of selector type $wpt",
674+
d"Pattern type $unapplyArgType is neither a subtype nor a supertype of selector type $wpt",
675675
tree.pos)
676676
}
677677

@@ -692,7 +692,7 @@ trait Applications extends Compatibility { self: Typer =>
692692
case _ => args
693693
}
694694
if (argTypes.length != bunchedArgs.length) {
695-
ctx.error(i"wrong number of argument patterns for $qual; expected: ($argTypes%, %)", tree.pos)
695+
ctx.error(d"wrong number of argument patterns for $qual; expected: ($argTypes%, %)", tree.pos)
696696
argTypes = argTypes.take(args.length) ++
697697
List.fill(argTypes.length - args.length)(WildcardType)
698698
}

src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import util.{Stats, SimpleMap}
1414
import util.common._
1515
import Decorators._
1616
import Uniques._
17-
import ErrorReporting.errorType
17+
import ErrorReporting.{errorType, DiagnosticString}
1818
import config.Printers._
1919
import collection.mutable
2020

@@ -40,7 +40,7 @@ trait Checking extends NoChecking {
4040
override def checkValue(tree: Tree, proto: Type)(implicit ctx: Context): tree.type = {
4141
if (!proto.isInstanceOf[SelectionProto]) {
4242
val sym = tree.tpe.termSymbol
43-
if ((sym is Package) || (sym is JavaModule)) ctx.error(i"$sym is not a value", tree.pos)
43+
if ((sym is Package) || (sym is JavaModule)) ctx.error(d"$sym is not a value", tree.pos)
4444
}
4545
tree
4646
}
@@ -51,21 +51,21 @@ trait Checking extends NoChecking {
5151
def substituted(tp: Type) = tp.substParams(poly, argTypes)
5252
for ((arg, bounds) <- args zip poly.paramBounds) {
5353
def notConforms(which: String, bound: Type) =
54-
ctx.error(i"Type argument ${arg.tpe} does not conform to $which bound $bound", arg.pos)
54+
ctx.error(d"Type argument ${arg.tpe} does not conform to $which bound $bound", arg.pos)
5555
if (!(arg.tpe <:< substituted(bounds.hi))) notConforms("upper", bounds.hi)
5656
if (!(bounds.lo <:< arg.tpe)) notConforms("lower", bounds.lo)
5757
}
5858
}
5959

6060
/** Check that type `tp` is stable. */
6161
override def checkStable(tp: Type, pos: Position)(implicit ctx: Context): Unit =
62-
if (!tp.isStable) ctx.error(i"$tp is not stable", pos)
62+
if (!tp.isStable) ctx.error(d"$tp is not stable", pos)
6363

6464
/** Check that type `tp` is a legal prefix for '#'.
6565
* @return The type itself
6666
*/
6767
override def checkLegalPrefix(tp: Type, pos: Position)(implicit ctx: Context): Unit =
68-
if (!tp.isLegalPrefix) ctx.error(i"$tp is not a valid prefix for '#'", pos)
68+
if (!tp.isLegalPrefix) ctx.error(d"$tp is not a valid prefix for '#'", pos)
6969

7070
/** Check that `tp` is a class type with a stable prefix. Also, if `isFirst` is
7171
* false check that `tp` is a trait.
@@ -75,10 +75,10 @@ trait Checking extends NoChecking {
7575
tp.underlyingClassRef match {
7676
case tref: TypeRef =>
7777
checkStable(tref.prefix, pos)
78-
if (traitReq && !(tref.symbol is Trait)) ctx.error(i"$tref is not a trait", pos)
78+
if (traitReq && !(tref.symbol is Trait)) ctx.error(d"$tref is not a trait", pos)
7979
tp
8080
case _ =>
81-
ctx.error(i"$tp is not a class type", pos)
81+
ctx.error(d"$tp is not a class type", pos)
8282
defn.ObjectClass.typeRef
8383
}
8484

@@ -87,7 +87,7 @@ trait Checking extends NoChecking {
8787
case tpt: untpd.DerivedTypeTree =>
8888
case TypeTree(untpd.EmptyTree) =>
8989
val resStr = if (defTree.isInstanceOf[untpd.DefDef]) "result " else ""
90-
ctx.error(i"${resStr}type of implicit definition needs to be given explicitly", defTree.pos)
90+
ctx.error(d"${resStr}type of implicit definition needs to be given explicitly", defTree.pos)
9191
case _ =>
9292
}
9393

@@ -109,7 +109,7 @@ trait Checking extends NoChecking {
109109
case tp: RefinedType =>
110110
tp.derivedRefinedType(tp.parent, tp.refinedName, checkFeasible(tp.refinedInfo, pos, where))
111111
case tp @ TypeBounds(lo, hi) if !(lo <:< hi) =>
112-
ctx.error(i"no type exists between low bound $lo and high bound $hi$where", pos)
112+
ctx.error(d"no type exists between low bound $lo and high bound $hi$where", pos)
113113
tp.derivedTypeAlias(hi)
114114
case _ =>
115115
tp
@@ -126,17 +126,17 @@ trait Checking extends NoChecking {
126126
typr.println(i"conflict? $decl $other")
127127
if (decl.signature matches other.signature) {
128128
def doubleDefError(decl: Symbol, other: Symbol): Unit = {
129-
def ofType = if (decl.isType) "" else i": ${other.info}"
129+
def ofType = if (decl.isType) "" else d": ${other.info}"
130130
def explanation =
131131
if (!decl.isSourceMethod) ""
132132
else "\n (both definitions have the same erased type signature)"
133-
ctx.error(i"$decl is already defined as $other$ofType$explanation", decl.pos)
133+
ctx.error(d"$decl is already defined as $other$ofType$explanation", decl.pos)
134134
}
135135
if (decl is Synthetic) doubleDefError(other, decl)
136136
else doubleDefError(decl, other)
137137
}
138138
if ((decl is HasDefaultParams) && (other is HasDefaultParams)) {
139-
ctx.error(i"two or more overloaded variants of $decl have default arguments")
139+
ctx.error(d"two or more overloaded variants of $decl have default arguments")
140140
decl resetFlag HasDefaultParams
141141
}
142142
}

src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object ErrorReporting {
3232
val treeSym = ctx.symOfContextTree(tree)
3333
if (treeSym.exists && treeSym.name == cycleSym.name && treeSym.owner == cycleSym.owner) {
3434
val result = if (cycleSym.isSourceMethod) " result" else ""
35-
i"overloaded or recursive $cycleSym needs$result type"
35+
d"overloaded or recursive $cycleSym needs$result type"
3636
}
3737
else errorMsg(msg, cx.outer)
3838
case _ =>
@@ -48,11 +48,11 @@ object ErrorReporting {
4848
case tp: FunProto =>
4949
val result = tp.resultType match {
5050
case tp: WildcardType => ""
51-
case tp => i"and expected result type $tp"
51+
case tp => d"and expected result type $tp"
5252
}
53-
i"arguments (${tp.typedArgs.tpes}%, %)$result"
53+
d"arguments (${tp.typedArgs.tpes}%, %)$result"
5454
case _ =>
55-
i"expected type $tp"
55+
d"expected type $tp"
5656
}
5757

5858
def anonymousTypeMemberStr(tpe: Type) = {
@@ -61,12 +61,12 @@ object ErrorReporting {
6161
case _: PolyType | _: MethodType => "method"
6262
case _ => "value of type"
6363
}
64-
i"$kind $tpe"
64+
d"$kind $tpe"
6565
}
6666

6767
def overloadedAltsStr(alts: List[SingleDenotation]) =
68-
i"overloaded alternatives of ${denotStr(alts.head)} with types\n" +
69-
i" ${alts map (_.info)}%\n %"
68+
d"overloaded alternatives of ${denotStr(alts.head)} with types\n" +
69+
d" ${alts map (_.info)}%\n %"
7070

7171
def denotStr(denot: Denotation): String =
7272
if (denot.isOverloaded) overloadedAltsStr(denot.alternatives)
@@ -96,7 +96,7 @@ object ErrorReporting {
9696
case tp: TypeRef => s"with info ${tp.info} / ${tp.prefix.toString} / ${tp.prefix.dealias.toString}"
9797
case _ => ""
9898
}
99-
i"""type mismatch:
99+
d"""type mismatch:
100100
| found : $found
101101
| required: $expected""".stripMargin + typerStateStr + explanationStr
102102
}
@@ -122,7 +122,7 @@ object ErrorReporting {
122122
case _ => true
123123
}
124124

125-
val s = new InfoString(sc).i(args)
125+
val s = new InfoString(sc).i(args : _*)
126126
if (args.forall(isSensical(_))) s else nonSensicalStartTag + s + nonSensicalEndTag
127127
}
128128
}

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ object Implicits {
204204
protected def pt: Type
205205
protected def argument: tpd.Tree
206206
protected def qualify(implicit ctx: Context) =
207-
if (argument.isEmpty) i"match type $pt"
208-
else i"convert from ${argument.tpe} to $pt"
207+
if (argument.isEmpty) d"match type $pt"
208+
else d"convert from ${argument.tpe} to $pt"
209209

210210
/** An explanation of the cause of the failure as a string */
211211
def explanation(implicit ctx: Context): String
@@ -214,25 +214,25 @@ object Implicits {
214214
/** An ambiguous implicits failure */
215215
class AmbiguousImplicits(alt1: TermRef, alt2: TermRef, val pt: Type, val argument: tpd.Tree) extends ExplainedSearchFailure {
216216
def explanation(implicit ctx: Context): String =
217-
i"both ${err.refStr(alt1)} and ${err.refStr(alt2)} $qualify"
217+
d"both ${err.refStr(alt1)} and ${err.refStr(alt2)} $qualify"
218218
override def postscript(implicit ctx: Context) =
219219
"\nNote that implicit conversions cannot be applied because they are ambiguous;" +
220220
"\n " + explanation
221221
}
222222

223223
class NonMatchingImplicit(ref: TermRef, val pt: Type, val argument: tpd.Tree) extends ExplainedSearchFailure {
224224
def explanation(implicit ctx: Context): String =
225-
i"${err.refStr(ref)} does not $qualify"
225+
d"${err.refStr(ref)} does not $qualify"
226226
}
227227

228228
class ShadowedImplicit(ref: TermRef, shadowing: Type, val pt: Type, val argument: tpd.Tree) extends ExplainedSearchFailure {
229229
def explanation(implicit ctx: Context): String =
230-
i"${err.refStr(ref)} does $qualify but is shadowed by ${err.refStr(shadowing)}"
230+
d"${err.refStr(ref)} does $qualify but is shadowed by ${err.refStr(shadowing)}"
231231
}
232232

233233
class DivergingImplicit(ref: TermRef, val pt: Type, val argument: tpd.Tree) extends ExplainedSearchFailure {
234234
def explanation(implicit ctx: Context): String =
235-
i"${err.refStr(ref)} produces a diverging implicit search when trying to $qualify"
235+
d"${err.refStr(ref)} produces a diverging implicit search when trying to $qualify"
236236
}
237237

238238
class FailedImplicit(failures: List[ExplainedSearchFailure], val pt: Type, val argument: tpd.Tree) extends ExplainedSearchFailure {
@@ -425,7 +425,7 @@ trait Implicits { self: Typer =>
425425
if (argument.isEmpty) f(resultType) else ViewProto(f(argument.tpe.widen), f(resultType))
426426

427427
assert(argument.isEmpty || argument.tpe.isValueType || argument.tpe.isInstanceOf[ExprType],
428-
i"found: ${argument.tpe}, expected: $pt")
428+
d"found: ${argument.tpe}, expected: $pt")
429429

430430
/** The expected type for the searched implicit */
431431
lazy val fullProto = implicitProto(pt, identity)

src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import util.{Stats, SimpleMap}
1515
import util.common._
1616
import Decorators._
1717
import Uniques._
18-
import ErrorReporting.errorType
18+
import ErrorReporting.{errorType, DiagnosticString}
1919
import config.Printers._
2020
import collection.mutable
2121

@@ -153,7 +153,7 @@ trait Inferencing { this: Checking =>
153153
case _ =>
154154
// add synthetic class type
155155
val first :: _ = ensureFirstIsClass(parents.tpes)
156-
TypeTree(checkFeasible(first, pos, i"\n in inferred parent $first")).withPos(pos) :: parents
156+
TypeTree(checkFeasible(first, pos, d"\n in inferred parent $first")).withPos(pos) :: parents
157157
}
158158

159159
/** Interpolate those undetermined type variables in the widened type of this tree

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Namer { typer: Typer =>
209209
ctx.error(s"${preExisting.showLocated} is compiled twice, runid = ${ctx.runId}", tree.pos)
210210
}
211211
else if ((!ctx.owner.isClass || name.isTypeName) && preExisting.exists) {
212-
ctx.error(i"$name is already defined as $preExisting")
212+
ctx.error(d"$name is already defined as $preExisting")
213213
}
214214
}
215215

src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ trait TypeAssigner {
118118
case sym :: Nil =>
119119
if (sym.owner == pre.typeSymbol) sym.show else sym.showLocated
120120
case _ =>
121-
i"none of the overloaded alternatives named $name"
121+
d"none of the overloaded alternatives named $name"
122122
}
123123
val where = if (ctx.owner.exists) s" from ${ctx.owner.enclosingClass}" else ""
124124
val whyNot = new StringBuffer
125125
alts foreach (_.isAccessibleFrom(pre, superAccess, whyNot))
126126
if (!tpe.isError)
127-
ctx.error(i"$what cannot be accessed as a member of $pre$where.$whyNot", pos)
127+
ctx.error(d"$what cannot be accessed as a member of $pre$where.$whyNot", pos)
128128
ErrorType
129129
}
130130
} else if (d.symbol is TypeParamAccessor) // always dereference type param accessors
@@ -145,8 +145,8 @@ trait TypeAssigner {
145145
else {
146146
if (!site.isErroneous) {
147147
ctx.error(
148-
if (name == nme.CONSTRUCTOR) i"$site does not have a constructor"
149-
else i"$name is not a member of $site", pos)
148+
if (name == nme.CONSTRUCTOR) d"$site does not have a constructor"
149+
else d"$name is not a member of $site", pos)
150150
}
151151
ErrorType
152152
}
@@ -202,7 +202,7 @@ trait TypeAssigner {
202202
case p :: Nil =>
203203
p
204204
case Nil =>
205-
errorType(i"$mix does not name a parent class of $cls", tree.pos)
205+
errorType(d"$mix does not name a parent class of $cls", tree.pos)
206206
case p :: q :: _ =>
207207
errorType(s"ambiguous parent class qualifier", tree.pos)
208208
}
@@ -229,7 +229,7 @@ trait TypeAssigner {
229229
case pt: PolyType =>
230230
val argTypes = args.tpes
231231
if (sameLength(argTypes, pt.paramNames)) pt.instantiate(args.tpes)
232-
else errorType(i"wrong number of type parameters for ${fn.tpe}; expected: ${pt.paramNames.length}", tree.pos)
232+
else errorType(d"wrong number of type parameters for ${fn.tpe}; expected: ${pt.paramNames.length}", tree.pos)
233233
case _ =>
234234
errorType(s"${err.exprStr(fn)} does not take type parameters", tree.pos)
235235
}
@@ -292,7 +292,7 @@ trait TypeAssigner {
292292
val tparams = tycon.tpe.typeParams
293293
val ownType =
294294
if (sameLength(tparams, args)) tycon.tpe.appliedTo(args.tpes)
295-
else errorType(i"wrong number of type arguments for ${tycon.tpe}, should be ${tparams.length}", tree.pos)
295+
else errorType(d"wrong number of type arguments for ${tycon.tpe}, should be ${tparams.length}", tree.pos)
296296
tree.withType(ownType)
297297
}
298298

0 commit comments

Comments
 (0)