Skip to content

Refactor "method does not take parameter" error message #4617

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
Jun 4, 2018
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
30 changes: 14 additions & 16 deletions compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1371,27 +1371,25 @@ object messages {
|"""
}

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

val msg = hl"${err.refStr(methPartType)} does not take$more parameters"
def methodSymbol = tpd.methPart(tree).symbol

val kind = "Reference"
val msg = {
val more = if (tree.isInstanceOf[tpd.Apply]) " more" else ""
hl"${methodSymbol.showLocated} does not take$more parameters"
}

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 = {
val isNullary = methodSymbol.info.isInstanceOf[ExprType]
val addendum =
if (isNullary) "\nNullary methods may not be called with parenthesis"
else ""

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@allanrenucci s/as defined/than defined/, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably. I reuse the same wording as in the initial error message. Feel free to open a new PR 😄

}

}

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 @@ -2133,7 +2133,7 @@ class Typer extends Namer
else
tree
case _ => tryInsertApplyOrImplicit(tree, pt, locked) {
errorTree(tree, MethodDoesNotTakeParameters(tree, methPart(tree).tpe)(err))
errorTree(tree, MethodDoesNotTakeParameters(tree))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ class ErrorMessagesTests extends ErrorMessagesTest {
implicit val ctx: Context = ictx

assertMessageCount(1, messages)
val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages
val msg @ MethodDoesNotTakeParameters(tree) = messages.head

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

@Test def methodDoesNotTakeMorePrameters =
Expand All @@ -366,10 +366,10 @@ class ErrorMessagesTests extends ErrorMessagesTest {
implicit val ctx: Context = ictx

assertMessageCount(1, messages)
val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages
val msg @ MethodDoesNotTakeParameters(tree) = messages.head

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

@Test def ambiugousOverloadWithWildcard =
Expand Down