Skip to content

Commit 0a7e6c9

Browse files
authored
Merge pull request #2825 from mikla/ref-1589-wrong-numbers-of-params-err
Refs #1589 Move "wrong number of parameters" error to a new errors fo…
2 parents e52095a + e3ad318 commit 0a7e6c9

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public enum ErrorMessageID {
9393
ModifiersNotAllowedID,
9494
WildcardOnTypeArgumentNotAllowedOnNewID,
9595
ImplicitFunctionTypeNeedsNonEmptyParameterListID,
96+
WrongNumberOfParametersID
9697
;
9798

9899
public int errorNumber() {

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

+7
Original file line numberDiff line numberDiff line change
@@ -1687,4 +1687,11 @@ object messages {
16871687
}
16881688
}
16891689

1690+
case class WrongNumberOfParameters(expected: Int)(implicit ctx: Context)
1691+
extends Message(WrongNumberOfParametersID) {
1692+
val kind = "Syntax"
1693+
val msg = s"wrong number of parameters, expected: $expected"
1694+
val explanation = ""
1695+
}
1696+
16901697
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
798798

799799
def protoFormal(i: Int): Type =
800800
if (protoFormals.length == params.length) protoFormals(i)
801-
else errorType(i"wrong number of parameters, expected: ${protoFormals.length}", tree.pos)
801+
else errorType(WrongNumberOfParameters(protoFormals.length), tree.pos)
802802

803803
/** Is `formal` a product type which is elementwise compatible with `params`? */
804804
def ptIsCorrectProduct(formal: Type) = {

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

+17
Original file line numberDiff line numberDiff line change
@@ -893,4 +893,21 @@ class ErrorMessagesTests extends ErrorMessagesTest {
893893
messages.foreach(assertEquals(_, ImplicitFunctionTypeNeedsNonEmptyParameterList()))
894894
}
895895

896+
@Test def wrongNumberOfParameters =
897+
checkMessagesAfter("refchecks") {
898+
"""object NumberOfParams {
899+
| def unary[T](x: T => Unit) = ()
900+
| unary((x, y) => ())
901+
|} """.stripMargin
902+
}
903+
.expect { (ictx, messages) =>
904+
implicit val ctx: Context = ictx
905+
val defn = ictx.definitions
906+
907+
assertMessageCount(1, messages)
908+
val err :: Nil = messages
909+
910+
assertEquals(err, WrongNumberOfParameters(1))
911+
}
912+
896913
}

0 commit comments

Comments
 (0)