Skip to content

Commit a9006c5

Browse files
committed
Fix "wrong number of args" reporting
"Wrong number of args" only works for type arguments but was called also for term arguments. Ideally we should have a WrongNumberOfArgs message that works for both, but this will take some refactoring.
1 parent 6115d66 commit a9006c5

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ object messages {
224224
extends Message(8) {
225225
val kind = "Member Not Found"
226226

227+
//println(i"site = $site, decls = ${site.decls}, source = ${site.widen.typeSymbol.sourceFile}") //DEBUG
228+
227229
val msg = {
228230
import core.Flags._
229231
val maxDist = 3
@@ -606,7 +608,7 @@ object messages {
606608
|"""
607609
}
608610

609-
case class WrongNumberOfArgs(fntpe: Type, argKind: String, expectedArgs: List[TypeParamInfo], actual: List[untpd.Tree])(implicit ctx: Context)
611+
case class WrongNumberOfTypeArgs(fntpe: Type, expectedArgs: List[TypeParamInfo], actual: List[untpd.Tree])(implicit ctx: Context)
610612
extends Message(22) {
611613
val kind = "Syntax"
612614

@@ -628,7 +630,7 @@ object messages {
628630
}
629631

630632
val msg =
631-
hl"""|${NoColor(msgPrefix)} ${argKind} arguments for $prettyName$expectedArgString
633+
hl"""|${NoColor(msgPrefix)} type arguments for $prettyName$expectedArgString
632634
|expected: $expectedArgString
633635
|actual: $actualArgString""".stripMargin
634636

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ object ErrorReporting {
4949
errorMsg(ex.show, ctx)
5050
}
5151

52-
def wrongNumberOfArgs(fntpe: Type, kind: String, expectedArgs: List[TypeParamInfo], actual: List[untpd.Tree], pos: Position)(implicit ctx: Context) =
53-
errorType(WrongNumberOfArgs(fntpe, kind, expectedArgs, actual)(ctx), pos)
52+
def wrongNumberOfTypeArgs(fntpe: Type, expectedArgs: List[TypeParamInfo], actual: List[untpd.Tree], pos: Position)(implicit ctx: Context) =
53+
errorType(WrongNumberOfTypeArgs(fntpe, expectedArgs, actual)(ctx), pos)
5454

5555
class Errors(implicit ctx: Context) {
5656

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ trait TypeAssigner {
314314
val ownType = fn.tpe.widen match {
315315
case fntpe @ MethodType(_, ptypes) =>
316316
if (sameLength(ptypes, args) || ctx.phase.prev.relaxedTyping) fntpe.instantiate(args.tpes)
317-
else wrongNumberOfArgs(fn.tpe, "", fntpe.typeParams, args, tree.pos)
317+
else
318+
errorType(i"wrong number of arguments for $fntpe: ${fn.tpe}, expected: ${ptypes.length}, found: ${args.length}", tree.pos)
318319
case t =>
319320
errorType(i"${err.exprStr(fn)} does not take parameters", tree.pos)
320321
}
@@ -369,7 +370,7 @@ trait TypeAssigner {
369370
else {
370371
val argTypes = args.tpes
371372
if (sameLength(argTypes, paramNames) || ctx.phase.prev.relaxedTyping) pt.instantiate(argTypes)
372-
else wrongNumberOfArgs(fn.tpe, "type", pt.typeParams, args, tree.pos)
373+
else wrongNumberOfTypeArgs(fn.tpe, pt.typeParams, args, tree.pos)
373374
}
374375
case _ =>
375376
errorType(i"${err.exprStr(fn)} does not take type parameters", tree.pos)
@@ -462,7 +463,7 @@ trait TypeAssigner {
462463
val ownType =
463464
if (hasNamedArg(args)) (tycon.tpe /: args)(refineNamed)
464465
else if (sameLength(tparams, args)) tycon.tpe.appliedTo(args.tpes)
465-
else wrongNumberOfArgs(tycon.tpe, "type", tparams, args, tree.pos)
466+
else wrongNumberOfTypeArgs(tycon.tpe, tparams, args, tree.pos)
466467
tree.withType(ownType)
467468
}
468469

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10561056
if (hasNamedArg(args)) typedNamedArgs(args)
10571057
else {
10581058
if (args.length != tparams.length) {
1059-
wrongNumberOfArgs(tpt1.tpe, "type", tparams, args, tree.pos)
1059+
wrongNumberOfTypeArgs(tpt1.tpe, tparams, args, tree.pos)
10601060
args = args.take(tparams.length)
10611061
}
10621062
def typedArg(arg: untpd.Tree, tparam: TypeParamInfo) = {

0 commit comments

Comments
 (0)