Skip to content

Drop String overloads in errorTree and errorType #16418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ object DesugarEnums {
def problem =
if (!tparam.isOneOf(VarianceFlags)) "is invariant"
else "has bounds that depend on a type parameter in the same parameter list"
errorType(i"""cannot determine type argument for enum parent $enumClass,
|type parameter $tparam $problem""", ctx.source.atSpan(span))
errorType(em"""cannot determine type argument for enum parent $enumClass,
|type parameter $tparam $problem""", ctx.source.atSpan(span))
}
}
TypeTree(enumClass.typeRef.appliedTo(targs)).withSpan(span)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ class Inliner(val call: tpd.Tree)(using Context):
private def inlineIfNeeded(tree: Tree)(using Context): Tree =
val meth = tree.symbol
if meth.isAllOf(DeferredInline) then
errorTree(tree, i"Deferred inline ${meth.showLocated} cannot be invoked")
errorTree(tree, em"Deferred inline ${meth.showLocated} cannot be invoked")
else if Inlines.needsInlining(tree) then Inlines.inlineCall(tree)
else tree

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase

def checkNotPackage(tree: Tree)(using Context): Tree =
if !tree.symbol.is(Package) then tree
else errorTree(tree, i"${tree.symbol} cannot be used as a type")
else errorTree(tree, em"${tree.symbol} cannot be used as a type")

override def transform(tree: Tree)(using Context): Tree =
try tree match {
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object Applications {
def extractorMemberType(tp: Type, name: Name, errorPos: SrcPos)(using Context): Type = {
val ref = extractorMember(tp, name)
if (ref.isOverloaded)
errorType(i"Overloaded reference to $ref is not allowed in extractor", errorPos)
errorType(em"Overloaded reference to $ref is not allowed in extractor", errorPos)
ref.info.widenExpr.annotatedToRepeated
}

Expand Down Expand Up @@ -1134,14 +1134,14 @@ trait Applications extends Compatibility {

def typedTypeApply(tree: untpd.TypeApply, pt: Type)(using Context): Tree = {
if (ctx.mode.is(Mode.Pattern))
return errorTree(tree, "invalid pattern")
return errorTree(tree, em"invalid pattern")

val isNamed = hasNamedArg(tree.args)
val typedArgs = if (isNamed) typedNamedArgs(tree.args) else tree.args.mapconserve(typedType(_))
record("typedTypeApply")
typedExpr(tree.fun, PolyProto(typedArgs, pt)) match {
case _: TypeApply if !ctx.isAfterTyper =>
errorTree(tree, "illegal repeated type application")
errorTree(tree, em"illegal repeated type application")
case typedFn =>
typedFn.tpe.widen match {
case pt: PolyType =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ object Checking {
checker.traverse(tpt.tpe)

def checkNoWildcard(tree: Tree)(using Context): Tree = tree.tpe match {
case tpe: TypeBounds => errorTree(tree, "no wildcard type allowed here")
case tpe: TypeBounds => errorTree(tree, em"no wildcard type allowed here")
case _ => tree
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Dynamic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ trait Dynamic {
val args = tree.args
val dynName = if (args.exists(isNamedArg)) nme.applyDynamicNamed else nme.applyDynamic
if (dynName == nme.applyDynamicNamed && untpd.isWildcardStarArgList(args))
errorTree(tree, "applyDynamicNamed does not support passing a vararg parameter")
errorTree(tree, em"applyDynamicNamed does not support passing a vararg parameter")
else {
def namedArgTuple(name: String, arg: untpd.Tree) = untpd.Tuple(List(Literal(Constant(name)), arg))
def namedArgs = args.map {
Expand Down
16 changes: 5 additions & 11 deletions compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ object ErrorReporting {
def errorTree(tree: untpd.Tree, msg: Message)(using Context): tpd.Tree =
errorTree(tree, msg, tree.srcPos)

def errorTree(tree: untpd.Tree, msg: => String)(using Context): tpd.Tree =
errorTree(tree, msg.toMessage)

def errorTree(tree: untpd.Tree, msg: TypeError, pos: SrcPos)(using Context): tpd.Tree =
tree.withType(errorType(msg, pos))

Expand All @@ -35,9 +32,6 @@ object ErrorReporting {
ErrorType(msg)
}

def errorType(msg: => String, pos: SrcPos)(using Context): ErrorType =
errorType(msg.toMessage, pos)

def errorType(ex: TypeError, pos: SrcPos)(using Context): ErrorType = {
report.error(ex, pos)
ErrorType(ex.toMessage)
Expand Down Expand Up @@ -147,11 +141,11 @@ object ErrorReporting {

def exprStr(tree: Tree): String = refStr(tree.tpe)

def takesNoParamsStr(tree: Tree, kind: String): String =
def takesNoParamsMsg(tree: Tree, kind: String): Message =
if (tree.tpe.widen.exists)
i"${exprStr(tree)} does not take ${kind}parameters"
em"${exprStr(tree)} does not take ${kind}parameters"
else {
i"undefined: $tree # ${tree.uniqueId}: ${tree.tpe.toString} at ${ctx.phase}"
em"undefined: $tree # ${tree.uniqueId}: ${tree.tpe.toString} at ${ctx.phase}"
}

def patternConstrStr(tree: Tree): String = ???
Expand Down Expand Up @@ -272,9 +266,9 @@ object ErrorReporting {
ownerSym.typeRef.nonClassTypeMembers.map(_.symbol)
}.toList

def dependentStr =
def dependentMsg =
"""Term-dependent types are experimental,
|they must be enabled with a `experimental.dependent` language import or setting""".stripMargin
|they must be enabled with a `experimental.dependent` language import or setting""".stripMargin.toMessage

def err(using Context): Errors = new Errors
}
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ trait TypeAssigner {
val cls = qualifyingClass(tree, tree.qual.name, packageOK = false)
tree.withType(
if (cls.isClass) cls.thisType
else errorType("not a legal qualifying class for this", tree.srcPos))
else errorType(em"not a legal qualifying class for this", tree.srcPos))
}

def superType(qualType: Type, mix: untpd.Ident, mixinClass: Symbol, pos: SrcPos)(using Context) =
Expand All @@ -240,7 +240,7 @@ trait TypeAssigner {
case Nil =>
errorType(SuperQualMustBeParent(mix, cls), pos)
case p :: q :: _ =>
errorType("ambiguous parent class qualifier", pos)
errorType(em"ambiguous parent class qualifier", pos)
}
val owntype =
if (mixinClass.exists) mixinClass.typeRef
Expand Down Expand Up @@ -288,16 +288,16 @@ trait TypeAssigner {
if (fntpe.paramInfos.hasSameLengthAs(args) || ctx.phase.prev.relaxedTyping)
safeSubstMethodParams(fntpe, args.tpes)
else
errorType(i"wrong number of arguments at ${ctx.phase.prev} for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.srcPos)
errorType(em"wrong number of arguments at ${ctx.phase.prev} for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.srcPos)
case t =>
if (ctx.settings.Ydebug.value) new FatalError("").printStackTrace()
errorType(err.takesNoParamsStr(fn, ""), tree.srcPos)
errorType(err.takesNoParamsMsg(fn, ""), tree.srcPos)
}
ConstFold.Apply(tree.withType(ownType))
}

def assignType(tree: untpd.TypeApply, fn: Tree, args: List[Tree])(using Context): TypeApply = {
def fail = tree.withType(errorType(err.takesNoParamsStr(fn, "type "), tree.srcPos))
def fail = tree.withType(errorType(err.takesNoParamsMsg(fn, "type "), tree.srcPos))
ConstFold(fn.tpe.widen match {
case pt: TypeLambda =>
tree.withType {
Expand Down
24 changes: 12 additions & 12 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
javaSelectOnType(qual2)

case _ =>
errorTree(tree, "cannot convert to type selection") // will never be printed due to fallback
errorTree(tree, em"cannot convert to type selection") // will never be printed due to fallback
}

def selectWithFallback(fallBack: Context ?=> Tree) =
Expand Down Expand Up @@ -1534,8 +1534,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case _ =>
if (mt.isParamDependent)
errorTree(tree,
i"""cannot turn method type $mt into closure
|because it has internal parameter dependencies""")
em"""cannot turn method type $mt into closure
|because it has internal parameter dependencies""")
else if ((tree.tpt `eq` untpd.ContextualEmptyTree) && mt.paramNames.isEmpty)
// Note implicitness of function in target type since there are no method parameters that indicate it.
TypeTree(defn.FunctionOf(Nil, mt.resType, isContextual = true, isErased = false))
Expand Down Expand Up @@ -1783,7 +1783,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
var body1 = typedType(cdef.body, pt)
if !body1.isType then
assert(ctx.reporter.errorsReported)
body1 = TypeTree(errorType("<error: not a type>", cdef.srcPos))
body1 = TypeTree(errorType(em"<error: not a type>", cdef.srcPos))
assignType(cpy.CaseDef(cdef)(pat2, EmptyTree, body1), pat2, body1)
}
caseRest(using ctx.fresh.setFreshGADTBounds.setNewScope)
Expand Down Expand Up @@ -1931,7 +1931,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
.withType(
if isFullyDefined(pt, ForceDegree.flipBottom) then pt
else if ctx.reporter.errorsReported then UnspecifiedErrorType
else errorType(i"cannot infer type; expected type $pt is not fully defined", tree.srcPos))
else errorType(em"cannot infer type; expected type $pt is not fully defined", tree.srcPos))

def typedTypeTree(tree: untpd.TypeTree, pt: Type)(using Context): Tree =
tree match
Expand All @@ -1945,7 +1945,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
// untyped tree is no longer accessed after all
// accesses with typedTypeTree are done.
case None =>
errorTree(tree, "Something's wrong: missing original symbol for type tree")
errorTree(tree, em"Something's wrong: missing original symbol for type tree")
}
case _ =>
completeTypeTree(InferredTypeTree(), pt, tree)
Expand Down Expand Up @@ -1986,9 +1986,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
tree.args match
case arg :: _ if arg.isTerm =>
if Feature.dependentEnabled then
return errorTree(tree, i"Not yet implemented: T(...)")
return errorTree(tree, em"Not yet implemented: T(...)")
else
return errorTree(tree, dependentStr)
return errorTree(tree, dependentMsg)
case _ =>

val tpt1 = withoutMode(Mode.Pattern) {
Expand Down Expand Up @@ -2127,9 +2127,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

def typedTermLambdaTypeTree(tree: untpd.TermLambdaTypeTree)(using Context): Tree =
if Feature.dependentEnabled then
errorTree(tree, i"Not yet implemented: (...) =>> ...")
errorTree(tree, em"Not yet implemented: (...) =>> ...")
else
errorTree(tree, dependentStr)
errorTree(tree, dependentMsg)

def typedMatchTypeTree(tree: untpd.MatchTypeTree, pt: Type)(using Context): Tree = {
val bound1 =
Expand Down Expand Up @@ -2161,7 +2161,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

def typedBind(tree: untpd.Bind, pt: Type)(using Context): Tree = {
if !isFullyDefined(pt, ForceDegree.all) then
return errorTree(tree, i"expected type of $tree is not fully defined")
return errorTree(tree, em"expected type of $tree is not fully defined")
val body1 = typed(tree.body, pt)
body1 match {
case UnApply(fn, Nil, arg :: Nil)
Expand Down Expand Up @@ -3779,7 +3779,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
else
val meth = methPart(tree).symbol
if meth.isAllOf(DeferredInline) && !Inlines.inInlineMethod then
errorTree(tree, i"Deferred inline ${meth.showLocated} cannot be invoked")
errorTree(tree, em"Deferred inline ${meth.showLocated} cannot be invoked")
else if Inlines.needsInlining(tree) then
tree.tpe <:< wildApprox(pt)
val errorCount = ctx.reporter.errorCount
Expand Down
4 changes: 2 additions & 2 deletions tests/pos-with-compiler-cc/dotc/ast/DesugarEnums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ object DesugarEnums {
def problem =
if (!tparam.isOneOf(VarianceFlags)) "is invariant"
else "has bounds that depend on a type parameter in the same parameter list"
errorType(i"""cannot determine type argument for enum parent $enumClass,
|type parameter $tparam $problem""", ctx.source.atSpan(span))
errorType(em"""cannot determine type argument for enum parent $enumClass,
|type parameter $tparam $problem""", ctx.source.atSpan(span))
}
}
TypeTree(enumClass.typeRef.appliedTo(targs)).withSpan(span)
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-with-compiler-cc/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ class Inliner(val call: tpd.Tree)(using Context):
private def inlineIfNeeded(tree: Tree)(using Context): Tree =
val meth = tree.symbol
if meth.isAllOf(DeferredInline) then
errorTree(tree, i"Deferred inline ${meth.showLocated} cannot be invoked")
errorTree(tree, em"Deferred inline ${meth.showLocated} cannot be invoked")
else if Inlines.needsInlining(tree) then Inlines.inlineCall(tree)
else tree

Expand Down
2 changes: 1 addition & 1 deletion tests/pos-with-compiler-cc/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase

def checkNotPackage(tree: Tree)(using Context): Tree =
if !tree.symbol.is(Package) then tree
else errorTree(tree, i"${tree.symbol} cannot be used as a type")
else errorTree(tree, em"${tree.symbol} cannot be used as a type")

override def transform(tree: Tree)(using Context): Tree =
try tree match {
Expand Down
6 changes: 3 additions & 3 deletions tests/pos-with-compiler-cc/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object Applications {
def extractorMemberType(tp: Type, name: Name, errorPos: SrcPos)(using Context): Type = {
val ref = extractorMember(tp, name)
if (ref.isOverloaded)
errorType(i"Overloaded reference to $ref is not allowed in extractor", errorPos)
errorType(em"Overloaded reference to $ref is not allowed in extractor", errorPos)
ref.info.widenExpr.annotatedToRepeated
}

Expand Down Expand Up @@ -1134,14 +1134,14 @@ trait Applications extends Compatibility {

def typedTypeApply(tree: untpd.TypeApply, pt: Type)(using Context): Tree = {
if (ctx.mode.is(Mode.Pattern))
return errorTree(tree, "invalid pattern")
return errorTree(tree, em"invalid pattern")

val isNamed = hasNamedArg(tree.args)
val typedArgs = if (isNamed) typedNamedArgs(tree.args) else tree.args.mapconserve(typedType(_))
record("typedTypeApply")
typedExpr(tree.fun, PolyProto(typedArgs, pt)) match {
case _: TypeApply if !ctx.isAfterTyper =>
errorTree(tree, "illegal repeated type application")
errorTree(tree, em"illegal repeated type application")
case typedFn =>
typedFn.tpe.widen match {
case pt: PolyType =>
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-with-compiler-cc/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ object Checking {
checker.traverse(tpt.tpe)

def checkNoWildcard(tree: Tree)(using Context): Tree = tree.tpe match {
case tpe: TypeBounds => errorTree(tree, "no wildcard type allowed here")
case tpe: TypeBounds => errorTree(tree, em"no wildcard type allowed here")
case _ => tree
}

Expand Down
2 changes: 1 addition & 1 deletion tests/pos-with-compiler-cc/dotc/typer/Dynamic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ trait Dynamic {
val args = tree.args
val dynName = if (args.exists(isNamedArg)) nme.applyDynamicNamed else nme.applyDynamic
if (dynName == nme.applyDynamicNamed && untpd.isWildcardStarArgList(args))
errorTree(tree, "applyDynamicNamed does not support passing a vararg parameter")
errorTree(tree, em"applyDynamicNamed does not support passing a vararg parameter")
else {
def namedArgTuple(name: String, arg: untpd.Tree) = untpd.Tuple(List(Literal(Constant(name)), arg))
def namedArgs = args.map {
Expand Down
16 changes: 5 additions & 11 deletions tests/pos-with-compiler-cc/dotc/typer/ErrorReporting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ object ErrorReporting {
def errorTree(tree: untpd.Tree, msg: Message)(using Context): tpd.Tree =
errorTree(tree, msg, tree.srcPos)

def errorTree(tree: untpd.Tree, msg: -> String)(using Context): tpd.Tree =
errorTree(tree, msg.toMessage)

def errorTree(tree: untpd.Tree, msg: TypeError, pos: SrcPos)(using Context): tpd.Tree =
tree.withType(errorType(msg, pos))

Expand All @@ -35,9 +32,6 @@ object ErrorReporting {
ErrorType(msg)
}

def errorType(msg: -> String, pos: SrcPos)(using Context): ErrorType =
errorType(msg.toMessage, pos)

def errorType(ex: TypeError, pos: SrcPos)(using Context): ErrorType = {
report.error(ex, pos)
ErrorType(ex.toMessage)
Expand Down Expand Up @@ -147,11 +141,11 @@ object ErrorReporting {

def exprStr(tree: Tree): String = refStr(tree.tpe)

def takesNoParamsStr(tree: Tree, kind: String): String =
def takesNoParamsMsg(tree: Tree, kind: String): Message =
if (tree.tpe.widen.exists)
i"${exprStr(tree)} does not take ${kind}parameters"
em"${exprStr(tree)} does not take ${kind}parameters"
else {
i"undefined: $tree # ${tree.uniqueId}: ${tree.tpe.toString} at ${ctx.phase}"
em"undefined: $tree # ${tree.uniqueId}: ${tree.tpe.toString} at ${ctx.phase}"
}

def patternConstrStr(tree: Tree): String = ???
Expand Down Expand Up @@ -272,9 +266,9 @@ object ErrorReporting {
ownerSym.typeRef.nonClassTypeMembers.map(_.symbol)
}.toList

def dependentStr =
def dependentMsg =
"""Term-dependent types are experimental,
|they must be enabled with a `experimental.dependent` language import or setting""".stripMargin
|they must be enabled with a `experimental.dependent` language import or setting""".stripMargin.toMessage

def err(using Context): Errors = new Errors
}
Loading