Skip to content

Commit 9c5e216

Browse files
committed
Moved Method Does Not Take (More) Parameters error to case class
1 parent ae4f1fa commit 9c5e216

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-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
@@ -57,6 +57,7 @@ public enum ErrorMessageID {
5757
CyclicReferenceInvolvingImplicitID,
5858
SuperQualMustBeParentID,
5959
AmbiguousImportID,
60+
MethodDoesNotTakeParametersId,
6061
;
6162

6263
public int errorNumber() {

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,4 +1253,21 @@ object messages {
12531253
|"""
12541254
}
12551255

1256+
case class MethodDoesNotTakeParameters(tree: tpd.Tree, methPartType: Types.Type)(err: typer.ErrorReporting.Errors)(implicit ctx: Context)
1257+
extends Message(MethodDoesNotTakeParametersId) {
1258+
private val more = tree match {
1259+
case Apply(_, _) => " more"
1260+
case _ => ""
1261+
}
1262+
1263+
val msg = hl"${err.refStr(methPartType)} does not take$more parameters"
1264+
1265+
val kind = "Reference"
1266+
1267+
val explanation =
1268+
hl"""|You have specified more parameter lists as defined in the method definition(s).
1269+
|In case ${err.refStr(methPartType)} is defined without parenthesis, you may
1270+
|not use any at call-site, either.
1271+
|"""
1272+
}
12561273
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,11 +1838,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18381838
else
18391839
tree
18401840
case _ => tryInsertApplyOrImplicit(tree, pt) {
1841-
val more = tree match {
1842-
case Apply(_, _) => " more"
1843-
case _ => ""
1844-
}
1845-
errorTree(tree, em"$methodStr does not take$more parameters")
1841+
errorTree(tree, MethodDoesNotTakeParameters(tree, methPart(tree).tpe)(err))
18461842
}
18471843
}
18481844

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,45 @@ class ErrorMessagesTests extends ErrorMessagesTest {
358358
assertEquals(namedImport, newPrec)
359359
assertEquals(namedImport, prevPrec)
360360
}
361+
362+
@Test def methodDoesNotTakePrameters =
363+
checkMessagesAfter("frontend") {
364+
"""
365+
|object Scope{
366+
| def foo = ()
367+
| foo()
368+
|}
369+
""".stripMargin
370+
}
371+
.expect { (ictx, messages) =>
372+
implicit val ctx: Context = ictx
373+
val defn = ictx.definitions
374+
375+
assertMessageCount(1, messages)
376+
val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages
377+
378+
assertEquals("Scope.foo", tree.show)
379+
assertEquals("=> Unit(Scope.foo)", methodPart.show)
380+
}
381+
382+
@Test def methodDoesNotTakeMorePrameters =
383+
checkMessagesAfter("frontend") {
384+
"""
385+
|object Scope{
386+
| def foo(a: Int) = ()
387+
| foo(1)("2")
388+
|}
389+
""".stripMargin
390+
}
391+
.expect { (ictx, messages) =>
392+
implicit val ctx: Context = ictx
393+
val defn = ictx.definitions
394+
395+
assertMessageCount(1, messages)
396+
val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages
397+
398+
assertEquals("Scope.foo(1)", tree.show)
399+
assertEquals("((a: Int)Unit)(Scope.foo)", methodPart.show)
400+
}
401+
361402
}

0 commit comments

Comments
 (0)