Skip to content
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

Better error message for arity mismatch #17955

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1739,10 +1739,12 @@ class NotAPath(tp: Type, usage: String)(using Context) extends TypeMsg(NotAPathI
| - a reference to `this`, or
| - a selection of an immutable path with an immutable value."""

class WrongNumberOfParameters(expected: Int)(using Context)
class WrongNumberOfParameters(expected: Int, found: Int, pt: Type, tree: tpd.Tree)(using Context)
extends SyntaxMsg(WrongNumberOfParametersID) {
def msg(using Context) = s"Wrong number of parameters, expected: $expected"
def explain(using Context) = ""
def msg(using Context) = s"Wrong number of parameters, expected $expected, but found $found"
def explain(using Context) =
i"""|Expected pattern: $pt
|Found pattern : ${tree.srcPos}"""
}

class DuplicatePrivateProtectedQualifier()(using Context)
Expand Down
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 @@ -1569,7 +1569,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
/** Returns the type and whether the parameter is erased */
def protoFormal(i: Int): (Type, Boolean) =
if (protoFormals.length == params.length) (protoFormals(i), isDefinedErased(i))
else (errorType(WrongNumberOfParameters(protoFormals.length), tree.srcPos), false)
else (errorType(WrongNumberOfParameters(protoFormals.length, params.length, pt, tree), tree.srcPos), false)

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