Skip to content

Commit 27f9856

Browse files
committed
Convert reporting arguments to messages
Using Message instead of String for arguments of report methods. String versions are still retained for external interop. But they should be used only if the argument is a simple string literal.
1 parent 9a9ce54 commit 27f9856

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+252
-233
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import dotty.tools.dotc.transform.SymUtils._
2323
import dotty.tools.dotc.util.Spans._
2424
import dotty.tools.dotc.core.Contexts._
2525
import dotty.tools.dotc.core.Phases._
26+
import dotty.tools.dotc.core.Decorators.em
2627
import dotty.tools.dotc.report
2728

2829
/*
@@ -700,7 +701,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
700701
var elemKind = arr.elementType
701702
val argsSize = args.length
702703
if (argsSize > dims) {
703-
report.error(s"too many arguments for array constructor: found ${args.length} but array has only $dims dimension(s)", ctx.source.atSpan(app.span))
704+
report.error(em"too many arguments for array constructor: found ${args.length} but array has only $dims dimension(s)", ctx.source.atSpan(app.span))
704705
}
705706
if (argsSize < dims) {
706707
/* In one step:

compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
7979
outputDirectory
8080
} catch {
8181
case ex: Throwable =>
82-
report.error(s"Couldn't create file for class $cName\n${ex.getMessage}", ctx.source.atSpan(csym.span))
82+
report.error(em"Couldn't create file for class $cName\n${ex.getMessage}", ctx.source.atSpan(csym.span))
8383
null
8484
}
8585
}
@@ -871,10 +871,11 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
871871
try body
872872
catch {
873873
case ex: Throwable =>
874-
report.error(i"""|compiler bug: created invalid generic signature for $sym in ${sym.denot.owner.showFullName}
875-
|signature: $sig
876-
|if this is reproducible, please report bug at https://github.com/lampepfl/dotty/issues
877-
""".trim, sym.sourcePos)
874+
report.error(
875+
em"""|compiler bug: created invalid generic signature for $sym in ${sym.denot.owner.showFullName}
876+
|signature: $sig
877+
|if this is reproducible, please report bug at https://github.com/lampepfl/dotty/issues
878+
""", sym.sourcePos)
878879
throw ex
879880
}
880881
}

compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
748748

749749
if (params.size > MaximumJvmParameters) {
750750
// SI-7324
751-
report.error(s"Platform restriction: a parameter list's length cannot exceed $MaximumJvmParameters.", ctx.source.atSpan(methSymbol.span))
751+
report.error(em"Platform restriction: a parameter list's length cannot exceed $MaximumJvmParameters.", ctx.source.atSpan(methSymbol.span))
752752
return
753753
}
754754

@@ -800,9 +800,10 @@ trait BCodeSkelBuilder extends BCodeHelpers {
800800
val veryFirstProgramPoint = currProgramPoint()
801801

802802
if trimmedRhs == tpd.EmptyTree then
803-
report.error("Concrete method has no definition: " + dd + (
804-
if (ctx.settings.Ydebug.value) "(found: " + methSymbol.owner.info.decls.toList.mkString(", ") + ")"
805-
else ""),
803+
report.error(
804+
em"Concrete method has no definition: $dd${
805+
if (ctx.settings.Ydebug.value) "(found: " + methSymbol.owner.info.decls.toList.mkString(", ") + ")"
806+
else ""}",
806807
ctx.source.atSpan(NoSpan)
807808
)
808809
else

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Contexts._
1414
import Types._
1515
import Symbols._
1616
import Phases._
17+
import Decorators.em
1718

1819
import dotty.tools.dotc.util.ReadOnlyMap
1920
import dotty.tools.dotc.report
@@ -71,7 +72,7 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
7172
def _1: Type = field.tpe match {
7273
case JavaArrayType(elem) => elem
7374
case _ =>
74-
report.error(s"JavaSeqArray with type ${field.tpe} reached backend: $field", ctx.source.atSpan(field.span))
75+
report.error(em"JavaSeqArray with type ${field.tpe} reached backend: $field", ctx.source.atSpan(field.span))
7576
UnspecifiedErrorType
7677
}
7778
def _2: List[Tree] = field.elems

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import dotty.tools.dotc.sbt.ExtractDependencies
2121
import Contexts._
2222
import Phases._
2323
import Symbols._
24+
import Decorators.em
2425

2526
import java.io.DataOutputStream
2627
import java.nio.channels.ClosedByInterruptException
@@ -308,7 +309,7 @@ class GenBCodePipeline(val int: DottyBackendInterface, val primitives: DottyPrim
308309
getFileForClassfile(outF, cls.name, ".class")
309310
} catch {
310311
case e: FileConflictException =>
311-
report.error(s"error writing ${cls.name}: ${e.getMessage}")
312+
report.error(em"error writing ${cls.name}: ${e.getMessage}")
312313
null
313314
}
314315
} else null
@@ -608,11 +609,11 @@ class GenBCodePipeline(val int: DottyBackendInterface, val primitives: DottyPrim
608609
val method =
609610
s"${e.getClassName.replaceAll("/", ".")}.${e.getMethodName}"
610611
val msg =
611-
s"Generated bytecode for method '$method' is too large. Size: ${e.getCodeSize} bytes. Limit is 64KB"
612+
em"Generated bytecode for method '$method' is too large. Size: ${e.getCodeSize} bytes. Limit is 64KB"
612613
report.error(msg)
613614
case e: ClassTooLargeException =>
614615
val msg =
615-
s"Class '${e.getClassName.replaceAll("/", ".")}' is too large. Constant pool size: ${e.getConstantPoolCount}. Limit is 64K entries"
616+
em"Class '${e.getClassName.replaceAll("/", ".")}' is too large. Constant pool size: ${e.getConstantPoolCount}. Limit is 64K entries"
616617
report.error(msg)
617618

618619
}

compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Contexts._
88
import Names.TermName, StdNames._
99
import Types.{JavaArrayType, UnspecifiedErrorType, Type}
1010
import Symbols.{Symbol, NoSymbol}
11+
import Decorators.em
1112
import dotc.report
1213
import dotc.util.ReadOnlyMap
1314

@@ -66,7 +67,7 @@ class DottyPrimitives(ictx: Context) {
6667
case defn.ArrayOf(el) => el
6768
case JavaArrayType(el) => el
6869
case _ =>
69-
report.error(s"expected Array $tpe")
70+
report.error(em"expected Array $tpe")
7071
UnspecifiedErrorType
7172
}
7273

@@ -133,7 +134,7 @@ class DottyPrimitives(ictx: Context) {
133134
def addPrimitives(cls: Symbol, method: TermName, code: Int)(using Context): Unit = {
134135
val alts = cls.info.member(method).alternatives.map(_.symbol)
135136
if (alts.isEmpty)
136-
report.error(s"Unknown primitive method $cls.$method")
137+
report.error(em"Unknown primitive method $cls.$method")
137138
else alts foreach (s =>
138139
addPrimitive(s,
139140
s.info.paramInfoss match {

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3652,7 +3652,7 @@ class JSCodeGen()(using genCtx: Context) {
36523652
} else if (sym.isJSType) {
36533653
if (sym.is(Trait)) {
36543654
report.error(
3655-
s"isInstanceOf[${sym.fullName}] not supported because it is a JS trait",
3655+
em"isInstanceOf[${sym.fullName}] not supported because it is a JS trait",
36563656
pos)
36573657
js.BooleanLiteral(true)
36583658
} else {

compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
308308
if (isProp && methodSyms.nonEmpty) {
309309
val firstAlt = alts.head
310310
report.error(
311-
i"Conflicting properties and methods for ${classSym.fullName}::$name.",
311+
em"Conflicting properties and methods for ${classSym.fullName}::$name.",
312312
firstAlt.srcPos)
313313
implicit val pos = firstAlt.span
314314
js.JSPropertyDef(js.MemberFlags.empty, genExpr(name)(firstAlt.sourcePos), None, None)
@@ -612,7 +612,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
612612
val altsTypesInfo = alts.map(_.info.show).sorted.mkString("\n ")
613613

614614
report.error(
615-
s"Cannot disambiguate overloads for $fullKind $displayName with types\n $altsTypesInfo",
615+
em"Cannot disambiguate overloads for $fullKind $displayName with types\n $altsTypesInfo",
616616
pos)
617617
}
618618

compiler/src/dotty/tools/backend/sjs/JSPositions.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import java.net.{URI, URISyntaxException}
66

77
import dotty.tools.dotc.core._
88
import Contexts._
9+
import Decorators.em
910

1011
import dotty.tools.dotc.report
1112

@@ -31,7 +32,7 @@ class JSPositions()(using Context) {
3132
URIMap(from, to) :: Nil
3233
} catch {
3334
case e: URISyntaxException =>
34-
report.error(s"${e.getInput} is not a valid URI")
35+
report.error(em"${e.getInput} is not a valid URI")
3536
Nil
3637
}
3738
}

compiler/src/dotty/tools/backend/sjs/JSPrimitives.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Names.TermName
55
import Types._
66
import Contexts._
77
import Symbols._
8+
import Decorators.em
89

910
import dotty.tools.dotc.ast.tpd._
1011
import dotty.tools.backend.jvm.DottyPrimitives
@@ -90,7 +91,7 @@ class JSPrimitives(ictx: Context) extends DottyPrimitives(ictx) {
9091
def addPrimitives(cls: Symbol, method: TermName, code: Int)(using Context): Unit = {
9192
val alts = cls.info.member(method).alternatives.map(_.symbol)
9293
if (alts.isEmpty) {
93-
report.error(s"Unknown primitive method $cls.$method")
94+
report.error(em"Unknown primitive method $cls.$method")
9495
} else {
9596
for (s <- alts)
9697
addPrimitive(s, code)

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ object CompilationUnit {
131131
if (!mustExist)
132132
source
133133
else if (source.file.isDirectory) {
134-
report.error(s"expected file, received directory '${source.file.path}'")
134+
report.error(em"expected file, received directory '${source.file.path}'")
135135
NoSource
136136
}
137137
else if (!source.file.exists) {
138-
report.error(s"source file not found: ${source.file.path}")
138+
report.error(em"source file not found: ${source.file.path}")
139139
NoSource
140140
}
141141
else source

compiler/src/dotty/tools/dotc/Driver.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,18 @@ class Driver {
9494
val newEntries: List[String] = files
9595
.flatMap { file =>
9696
if !file.exists then
97-
report.error(s"File does not exist: ${file.path}")
97+
report.error(em"File does not exist: ${file.path}")
9898
None
9999
else file.extension match
100100
case "jar" => Some(file.path)
101101
case "tasty" =>
102102
TastyFileUtil.getClassPath(file) match
103103
case Some(classpath) => Some(classpath)
104104
case _ =>
105-
report.error(s"Could not load classname from: ${file.path}")
105+
report.error(em"Could not load classname from: ${file.path}")
106106
None
107107
case _ =>
108-
report.error(s"File extension is not `tasty` or `jar`: ${file.path}")
108+
report.error(em"File extension is not `tasty` or `jar`: ${file.path}")
109109
None
110110
}
111111
.distinct

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ object desugar {
911911
case params :: paramss1 => // `params` must have a single parameter and without `given` flag
912912

913913
def badRightAssoc(problem: String) =
914-
report.error(i"right-associative extension method $problem", mdef.srcPos)
914+
report.error(em"right-associative extension method $problem", mdef.srcPos)
915915
extParamss ++ mdef.paramss
916916

917917
params match
@@ -1237,7 +1237,7 @@ object desugar {
12371237
def checkOpaqueAlias(tree: MemberDef)(using Context): MemberDef =
12381238
def check(rhs: Tree): MemberDef = rhs match
12391239
case bounds: TypeBoundsTree if bounds.alias.isEmpty =>
1240-
report.error(i"opaque type must have a right-hand side", tree.srcPos)
1240+
report.error(em"opaque type must have a right-hand side", tree.srcPos)
12411241
tree.withMods(tree.mods.withoutFlags(Opaque))
12421242
case LambdaTypeTree(_, body) => check(body)
12431243
case _ => tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ object DesugarEnums {
216216
case Ident(name) =>
217217
val matches = tparamNames.contains(name)
218218
if (matches && (caseTypeParams.nonEmpty || vparamss.isEmpty))
219-
report.error(i"illegal reference to type parameter $name from enum case", tree.srcPos)
219+
report.error(em"illegal reference to type parameter $name from enum case", tree.srcPos)
220220
matches
221221
case LambdaTypeTree(lambdaParams, body) =>
222222
underBinders(lambdaParams, foldOver(x, tree))

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object MainProxies {
5656

5757
def addArgs(call: untpd.Tree, mt: MethodType, idx: Int): untpd.Tree =
5858
if (mt.isImplicitMethod) {
59-
report.error(s"@main method cannot have implicit parameters", pos)
59+
report.error(em"@main method cannot have implicit parameters", pos)
6060
call
6161
}
6262
else {
@@ -74,7 +74,7 @@ object MainProxies {
7474
mt.resType match {
7575
case restpe: MethodType =>
7676
if (mt.paramInfos.lastOption.getOrElse(NoType).isRepeatedParam)
77-
report.error(s"varargs parameter of @main method must come last", pos)
77+
report.error(em"varargs parameter of @main method must come last", pos)
7878
addArgs(call1, restpe, idx + args.length)
7979
case _ =>
8080
call1
@@ -83,17 +83,17 @@ object MainProxies {
8383

8484
var result: List[TypeDef] = Nil
8585
if (!mainFun.owner.isStaticOwner)
86-
report.error(s"@main method is not statically accessible", pos)
86+
report.error(em"@main method is not statically accessible", pos)
8787
else {
8888
var call = ref(mainFun.termRef)
8989
mainFun.info match {
9090
case _: ExprType =>
9191
case mt: MethodType =>
9292
call = addArgs(call, mt, 0)
9393
case _: PolyType =>
94-
report.error(s"@main method cannot have type parameters", pos)
94+
report.error(em"@main method cannot have type parameters", pos)
9595
case _ =>
96-
report.error(s"@main can only annotate a method", pos)
96+
report.error(em"@main can only annotate a method", pos)
9797
}
9898
val errVar = Ident(nme.error)
9999
val handler = CaseDef(
@@ -203,7 +203,7 @@ object MainProxies {
203203
))
204204
(sym, paramAnnotations.toVector, defaultValueSymbols(scope, sym), stat.rawComment) :: Nil
205205
case mainAnnot :: others =>
206-
report.error(s"method cannot have multiple main annotations", mainAnnot.tree)
206+
report.error(em"method cannot have multiple main annotations", mainAnnot.tree)
207207
Nil
208208
}
209209
case stat @ TypeDef(_, impl: Template) if stat.symbol.is(Module) =>
@@ -379,26 +379,26 @@ object MainProxies {
379379
end generateMainClass
380380

381381
if (!mainFun.owner.isStaticOwner)
382-
report.error(s"main method is not statically accessible", pos)
382+
report.error(em"main method is not statically accessible", pos)
383383
None
384384
else mainFun.info match {
385385
case _: ExprType =>
386386
Some(generateMainClass(unitToValue(ref(mainFun.termRef)), Nil, Nil))
387387
case mt: MethodType =>
388388
if (mt.isImplicitMethod)
389-
report.error(s"main method cannot have implicit parameters", pos)
389+
report.error(em"main method cannot have implicit parameters", pos)
390390
None
391391
else mt.resType match
392392
case restpe: MethodType =>
393-
report.error(s"main method cannot be curried", pos)
393+
report.error(em"main method cannot be curried", pos)
394394
None
395395
case _ =>
396396
Some(generateMainClass(unitToValue(Apply(ref(mainFun.termRef), argRefs(mt))), argValDefs(mt), parameterInfos(mt)))
397397
case _: PolyType =>
398-
report.error(s"main method cannot have type parameters", pos)
398+
report.error(em"main method cannot have type parameters", pos)
399399
None
400400
case _ =>
401-
report.error(s"main can only annotate a method", pos)
401+
report.error(em"main can only annotate a method", pos)
402402
None
403403
}
404404
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ object Trees {
17451745
val denot = receiver.tpe.member(method)
17461746
if !denot.exists then
17471747
overload.println(i"members = ${receiver.tpe.decls}")
1748-
report.error(i"no member $receiver . $method", receiver.srcPos)
1748+
report.error(em"no member $receiver . $method", receiver.srcPos)
17491749
val selected =
17501750
if (denot.isOverloaded) {
17511751
def typeParamCount(tp: Type) = tp.widen match {

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class CheckCaptures extends Recheck, SymTransformer:
203203
def checkElem(elem: CaptureRef, cs: CaptureSet, pos: SrcPos)(using Context) =
204204
val res = elem.singletonCaptureSet.subCaptures(cs, frozen = false)
205205
if !res.isOK then
206-
report.error(i"$elem cannot be referenced here; it is not included in the allowed capture set ${res.blocking}", pos)
206+
report.error(em"$elem cannot be referenced here; it is not included in the allowed capture set ${res.blocking}", pos)
207207

208208
/** Check subcapturing `cs1 <: cs2`, report error on failure */
209209
def checkSubset(cs1: CaptureSet, cs2: CaptureSet, pos: SrcPos)(using Context) =
@@ -212,7 +212,7 @@ class CheckCaptures extends Recheck, SymTransformer:
212212
def header =
213213
if cs1.elems.size == 1 then i"reference ${cs1.elems.toList}%, % is not"
214214
else i"references $cs1 are not all"
215-
report.error(i"$header included in allowed capture set ${res.blocking}", pos)
215+
report.error(em"$header included in allowed capture set ${res.blocking}", pos)
216216

217217
/** The current environment */
218218
private var curEnv: Env = Env(NoSymbol, nestedInOwner = false, CaptureSet.empty, isBoxed = false, null)
@@ -866,9 +866,9 @@ class CheckCaptures extends Recheck, SymTransformer:
866866
// Forbid inferred self types unless they are already implied by an explicit
867867
// self type in a parent.
868868
report.error(
869-
i"""$root needs an explicitly declared self type since its
870-
|inferred self type $selfType
871-
|is not visible in other compilation units that define subclasses.""",
869+
em"""$root needs an explicitly declared self type since its
870+
|inferred self type $selfType
871+
|is not visible in other compilation units that define subclasses.""",
872872
root.srcPos)
873873
case _ =>
874874
parentTrees -= root

0 commit comments

Comments
 (0)