Skip to content

Moved Method Does Not Take (More) Parameters error to case class #2357

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 3 commits into from
May 12, 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 @@ -57,6 +57,7 @@ public enum ErrorMessageID {
CyclicReferenceInvolvingImplicitID,
SuperQualMustBeParentID,
AmbiguousImportID,
MethodDoesNotTakeParametersId,
AmbiguousOverloadID,
ReassignmentToValID,
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,30 @@ object messages {
|"""
}

case class MethodDoesNotTakeParameters(tree: tpd.Tree, methPartType: Types.Type)(err: typer.ErrorReporting.Errors)(implicit ctx: Context)
extends Message(MethodDoesNotTakeParametersId) {
private val more = tree match {
case Apply(_, _) => " more"
case _ => ""
}

val msg = hl"${err.refStr(methPartType)} does not take$more parameters"

val kind = "Reference"

private val noParameters = if (methPartType.widenSingleton.isInstanceOf[ExprType])
hl"""|As ${err.refStr(methPartType)} is defined without parenthesis, you may
|not use any at call-site, either.
|"""
else
""

val explanation =
s"""|You have specified more parameter lists as defined in the method definition(s).
|$noParameters""".stripMargin

}

case class AmbiguousOverload(tree: tpd.Tree, alts: List[SingleDenotation], pt: Type)(
err: typer.ErrorReporting.Errors)(
implicit ctx: Context)
Expand Down Expand Up @@ -1283,5 +1307,4 @@ object messages {
| ${"var"} $name ${"="} ...
|""".stripMargin
}

}
6 changes: 1 addition & 5 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1834,11 +1834,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
else
tree
case _ => tryInsertApplyOrImplicit(tree, pt) {
val more = tree match {
case Apply(_, _) => " more"
case _ => ""
}
errorTree(tree, em"$methodStr does not take$more parameters")
errorTree(tree, MethodDoesNotTakeParameters(tree, methPart(tree).tpe)(err))
}
}

Expand Down
40 changes: 40 additions & 0 deletions compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,46 @@ class ErrorMessagesTests extends ErrorMessagesTest {
assertEquals(namedImport, prevPrec)
}

@Test def methodDoesNotTakePrameters =
checkMessagesAfter("frontend") {
"""
|object Scope{
| def foo = ()
| foo()
|}
""".stripMargin
}
.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
val defn = ictx.definitions

assertMessageCount(1, messages)
val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages

assertEquals("Scope.foo", tree.show)
assertEquals("=> Unit(Scope.foo)", methodPart.show)
}

@Test def methodDoesNotTakeMorePrameters =
checkMessagesAfter("frontend") {
"""
|object Scope{
| def foo(a: Int) = ()
| foo(1)("2")
|}
""".stripMargin
}
.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
val defn = ictx.definitions

assertMessageCount(1, messages)
val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages

assertEquals("Scope.foo(1)", tree.show)
assertEquals("((a: Int)Unit)(Scope.foo)", methodPart.show)
}

@Test def ambiugousOverloadWithWildcard =
checkMessagesAfter("frontend") {
"""object Context {
Expand Down