Skip to content

Commit 77a04b2

Browse files
replace i"..." by d"..." if string might go into a
Diagnostic and might be nonsensical Conflicts: src/dotty/tools/dotc/typer/Checking.scala src/dotty/tools/dotc/typer/TypeAssigner.scala
1 parent e4ee662 commit 77a04b2

File tree

9 files changed

+59
-58
lines changed

9 files changed

+59
-58
lines changed

src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import core.Symbols._
1010
import core.Types._
1111
import core.Constants._
1212
import core.StdNames._
13+
import core.Decorators._
1314
import core.transform.Erasure.isUnboundedGeneric
1415
import typer.ErrorReporting._
1516
import ast.Trees._

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

@@ -27,7 +27,7 @@ trait Checking {
2727
def checkValue(tree: Tree, proto: Type)(implicit ctx: Context): tree.type = {
2828
if (!proto.isInstanceOf[SelectionProto]) {
2929
val sym = tree.tpe.termSymbol
30-
if ((sym is Package) || (sym is JavaModule)) ctx.error(i"$sym is not a value", tree.pos)
30+
if ((sym is Package) || (sym is JavaModule)) ctx.error(d"$sym is not a value", tree.pos)
3131
}
3232
tree
3333
}
@@ -38,21 +38,21 @@ trait Checking {
3838
def substituted(tp: Type) = tp.substParams(poly, argTypes)
3939
for ((arg, bounds) <- args zip poly.paramBounds) {
4040
def notConforms(which: String, bound: Type) =
41-
ctx.error(i"Type argument ${arg.tpe} does not conform to $which bound $bound", arg.pos)
41+
ctx.error(d"Type argument ${arg.tpe} does not conform to $which bound $bound", arg.pos)
4242
if (!(arg.tpe <:< substituted(bounds.hi))) notConforms("upper", bounds.hi)
4343
if (!(bounds.lo <:< arg.tpe)) notConforms("lower", bounds.lo)
4444
}
4545
}
4646

4747
/** Check that type `tp` is stable. */
4848
def checkStable(tp: Type, pos: Position)(implicit ctx: Context): Unit =
49-
if (!tp.isStable) ctx.error(i"$tp is not stable", pos)
49+
if (!tp.isStable) ctx.error(d"$tp is not stable", pos)
5050

5151
/** Check that type `tp` is a legal prefix for '#'.
5252
* @return The type itself
5353
*/
5454
def checkLegalPrefix(tp: Type, pos: Position)(implicit ctx: Context): Unit =
55-
if (!tp.isLegalPrefix) ctx.error(i"$tp is not a valid prefix for '#'", pos)
55+
if (!tp.isLegalPrefix) ctx.error(d"$tp is not a valid prefix for '#'", pos)
5656

5757
/** Check that `tp` is a class type with a stable prefix. Also, if `isFirst` is
5858
* false check that `tp` is a trait.
@@ -62,10 +62,10 @@ trait Checking {
6262
tp.underlyingClassRef match {
6363
case tref: TypeRef =>
6464
checkStable(tref.prefix, pos)
65-
if (traitReq && !(tref.symbol is Trait)) ctx.error(i"$tref is not a trait", pos)
65+
if (traitReq && !(tref.symbol is Trait)) ctx.error(d"$tref is not a trait", pos)
6666
tp
6767
case _ =>
68-
ctx.error(i"$tp is not a class type", pos)
68+
ctx.error(d"$tp is not a class type", pos)
6969
defn.ObjectClass.typeRef
7070
}
7171

@@ -74,7 +74,7 @@ trait Checking {
7474
case tpt: untpd.DerivedTypeTree =>
7575
case TypeTree(untpd.EmptyTree) =>
7676
val resStr = if (defTree.isInstanceOf[untpd.DefDef]) "result " else ""
77-
ctx.error(i"${resStr}type of implicit definition needs to be given explicitly", defTree.pos)
77+
ctx.error(d"${resStr}type of implicit definition needs to be given explicitly", defTree.pos)
7878
case _ =>
7979
}
8080

@@ -96,7 +96,7 @@ trait Checking {
9696
case tp: RefinedType =>
9797
tp.derivedRefinedType(tp.parent, tp.refinedName, checkFeasible(tp.refinedInfo, pos, where))
9898
case tp @ TypeBounds(lo, hi) if !(lo <:< hi) =>
99-
ctx.error(i"no type exists between low bound $lo and high bound $hi$where", pos)
99+
ctx.error(d"no type exists between low bound $lo and high bound $hi$where", pos)
100100
tp.derivedTypeAlias(hi)
101101
case _ =>
102102
tp
@@ -113,17 +113,17 @@ trait Checking {
113113
typr.println(i"conflict? $decl $other")
114114
if (decl.signature matches other.signature) {
115115
def doubleDefError(decl: Symbol, other: Symbol): Unit = {
116-
def ofType = if (decl.isType) "" else i": ${other.info}"
116+
def ofType = if (decl.isType) "" else d": ${other.info}"
117117
def explanation =
118118
if (!decl.isSourceMethod) ""
119119
else "\n (both definitions have the same erased type signature)"
120-
ctx.error(i"$decl is already defined as $other$ofType$explanation", decl.pos)
120+
ctx.error(d"$decl is already defined as $other$ofType$explanation", decl.pos)
121121
}
122122
if (decl is Synthetic) doubleDefError(other, decl)
123123
else doubleDefError(decl, other)
124124
}
125125
if ((decl is HasDefaultParams) && (other is HasDefaultParams)) {
126-
ctx.error(i"two or more overloaded variants of $decl have default arguments")
126+
ctx.error(d"two or more overloaded variants of $decl have default arguments")
127127
decl resetFlag HasDefaultParams
128128
}
129129
}

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(argTypes)
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
}
@@ -296,7 +296,7 @@ trait TypeAssigner {
296296
val tparams = tycon.tpe.typeParams
297297
val ownType =
298298
if (sameLength(tparams, args)) tycon.tpe.appliedTo(args.tpes)
299-
else errorType(i"wrong number of type arguments for ${tycon.tpe}, should be ${tparams.length}", tree.pos)
299+
else errorType(d"wrong number of type arguments for ${tycon.tpe}, should be ${tparams.length}", tree.pos)
300300
tree.withType(ownType)
301301
}
302302

0 commit comments

Comments
 (0)