Skip to content

Refs #1589 Move "wrong number of parameters" error to a new errors fo… #2825

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 1 commit into from
Jul 4, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public enum ErrorMessageID {
ModifiersNotAllowedID,
WildcardOnTypeArgumentNotAllowedOnNewID,
ImplicitFunctionTypeNeedsNonEmptyParameterListID,
WrongNumberOfParametersID
;

public int errorNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1687,4 +1687,11 @@ object messages {
}
}

case class WrongNumberOfParameters(expected: Int)(implicit ctx: Context)
extends Message(WrongNumberOfParametersID) {
val kind = "Syntax"
val msg = s"wrong number of parameters, expected: $expected"
val explanation = ""
}

}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit

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

/** Is `formal` a product type which is elementwise compatible with `params`? */
def ptIsCorrectProduct(formal: Type) = {
Expand Down
17 changes: 17 additions & 0 deletions compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -893,4 +893,21 @@ class ErrorMessagesTests extends ErrorMessagesTest {
messages.foreach(assertEquals(_, ImplicitFunctionTypeNeedsNonEmptyParameterList()))
}

@Test def wrongNumberOfParameters =
checkMessagesAfter("refchecks") {
"""object NumberOfParams {
| def unary[T](x: T => Unit) = ()
| unary((x, y) => ())
|} """.stripMargin
}
.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
val defn = ictx.definitions

assertMessageCount(1, messages)
val err :: Nil = messages

assertEquals(err, WrongNumberOfParameters(1))
}

}