Skip to content

Commit c7d92ba

Browse files
committed
Moved Method Does Not Take (More) Parameters error to case class
1 parent df22149 commit c7d92ba

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public enum ErrorMessageID {
5656
CyclicReferenceInvolvingID,
5757
CyclicReferenceInvolvingImplicitID,
5858
SuperQualMustBeParentID,
59+
MethodDoesNotTakeParametersId,
5960
;
6061

6162
public int errorNumber() {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,4 +1223,22 @@ object messages {
12231223
|Attempting to define a field in a method signature after a varargs field is an error.
12241224
|""".stripMargin
12251225
}
1226+
1227+
case class MethodDoesNotTakeParameters(tree: tpd.Tree, methPartType: Types.Type)(err: typer.ErrorReporting.Errors)(implicit ctx: Context)
1228+
extends Message(MethodDoesNotTakeParametersId) {
1229+
private val more = tree match {
1230+
case Apply(_, _) => " more"
1231+
case _ => ""
1232+
}
1233+
1234+
val msg = hl"${err.refStr(methPartType)} does not take$more parameters"
1235+
1236+
val kind = "Reference"
1237+
1238+
val explanation =
1239+
hl"""|You have specified more parameter lists as defined in the method definition(s).
1240+
|In case ${err.refStr(methPartType)} is defined without parenthesis, you may
1241+
|not use any at call-site, either.
1242+
|""".stripMargin
1243+
}
12261244
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,11 +1846,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18461846
else
18471847
tree
18481848
case _ => tryInsertApplyOrImplicit(tree, pt) {
1849-
val more = tree match {
1850-
case Apply(_, _) => " more"
1851-
case _ => ""
1852-
}
1853-
errorTree(tree, em"$methodStr does not take$more parameters")
1849+
errorTree(tree, MethodDoesNotTakeParameters(tree, methPart(tree).tpe)(err))
18541850
}
18551851
}
18561852

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,45 @@ class ErrorMessagesTests extends ErrorMessagesTest {
329329
assertEquals("B", qual.show)
330330
assertEquals("class C", cls.show)
331331
}
332+
333+
@Test def methodDoesNotTakePrameters =
334+
checkMessagesAfter("frontend") {
335+
"""
336+
|object Scope{
337+
| def foo = ()
338+
| foo()
339+
|}
340+
""".stripMargin
341+
}
342+
.expect { (ictx, messages) =>
343+
implicit val ctx: Context = ictx
344+
val defn = ictx.definitions
345+
346+
assertMessageCount(1, messages)
347+
val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages
348+
349+
assertEquals("Scope.foo", tree.show)
350+
assertEquals("=> Unit(Scope.foo)", methodPart.show)
351+
}
352+
353+
@Test def methodDoesNotTakeMorePrameters =
354+
checkMessagesAfter("frontend") {
355+
"""
356+
|object Scope{
357+
| def foo(a: Int) = ()
358+
| foo(1)("2")
359+
|}
360+
""".stripMargin
361+
}
362+
.expect { (ictx, messages) =>
363+
implicit val ctx: Context = ictx
364+
val defn = ictx.definitions
365+
366+
assertMessageCount(1, messages)
367+
val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages
368+
369+
assertEquals("Scope.foo(1)", tree.show)
370+
assertEquals("((a: Int)Unit)(Scope.foo)", methodPart.show)
371+
}
372+
332373
}

0 commit comments

Comments
 (0)