Skip to content

Commit ff88246

Browse files
authored
Merge pull request #2357 from ennru/ennru_MethodDoesNotTakeParameters
Moved Method Does Not Take (More) Parameters error to case class
2 parents d62607f + fb4daf8 commit ff88246

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
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
AmbiguousOverloadID,
6162
ReassignmentToValID,
6263
;

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,30 @@ object messages {
12511251
|"""
12521252
}
12531253

1254+
case class MethodDoesNotTakeParameters(tree: tpd.Tree, methPartType: Types.Type)(err: typer.ErrorReporting.Errors)(implicit ctx: Context)
1255+
extends Message(MethodDoesNotTakeParametersId) {
1256+
private val more = tree match {
1257+
case Apply(_, _) => " more"
1258+
case _ => ""
1259+
}
1260+
1261+
val msg = hl"${err.refStr(methPartType)} does not take$more parameters"
1262+
1263+
val kind = "Reference"
1264+
1265+
private val noParameters = if (methPartType.widenSingleton.isInstanceOf[ExprType])
1266+
hl"""|As ${err.refStr(methPartType)} is defined without parenthesis, you may
1267+
|not use any at call-site, either.
1268+
|"""
1269+
else
1270+
""
1271+
1272+
val explanation =
1273+
s"""|You have specified more parameter lists as defined in the method definition(s).
1274+
|$noParameters""".stripMargin
1275+
1276+
}
1277+
12541278
case class AmbiguousOverload(tree: tpd.Tree, alts: List[SingleDenotation], pt: Type)(
12551279
err: typer.ErrorReporting.Errors)(
12561280
implicit ctx: Context)
@@ -1283,5 +1307,4 @@ object messages {
12831307
| ${"var"} $name ${"="} ...
12841308
|""".stripMargin
12851309
}
1286-
12871310
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,11 +1834,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18341834
else
18351835
tree
18361836
case _ => tryInsertApplyOrImplicit(tree, pt) {
1837-
val more = tree match {
1838-
case Apply(_, _) => " more"
1839-
case _ => ""
1840-
}
1841-
errorTree(tree, em"$methodStr does not take$more parameters")
1837+
errorTree(tree, MethodDoesNotTakeParameters(tree, methPart(tree).tpe)(err))
18421838
}
18431839
}
18441840

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,46 @@ class ErrorMessagesTests extends ErrorMessagesTest {
360360
assertEquals(namedImport, prevPrec)
361361
}
362362

363+
@Test def methodDoesNotTakePrameters =
364+
checkMessagesAfter("frontend") {
365+
"""
366+
|object Scope{
367+
| def foo = ()
368+
| foo()
369+
|}
370+
""".stripMargin
371+
}
372+
.expect { (ictx, messages) =>
373+
implicit val ctx: Context = ictx
374+
val defn = ictx.definitions
375+
376+
assertMessageCount(1, messages)
377+
val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages
378+
379+
assertEquals("Scope.foo", tree.show)
380+
assertEquals("=> Unit(Scope.foo)", methodPart.show)
381+
}
382+
383+
@Test def methodDoesNotTakeMorePrameters =
384+
checkMessagesAfter("frontend") {
385+
"""
386+
|object Scope{
387+
| def foo(a: Int) = ()
388+
| foo(1)("2")
389+
|}
390+
""".stripMargin
391+
}
392+
.expect { (ictx, messages) =>
393+
implicit val ctx: Context = ictx
394+
val defn = ictx.definitions
395+
396+
assertMessageCount(1, messages)
397+
val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages
398+
399+
assertEquals("Scope.foo(1)", tree.show)
400+
assertEquals("((a: Int)Unit)(Scope.foo)", methodPart.show)
401+
}
402+
363403
@Test def ambiugousOverloadWithWildcard =
364404
checkMessagesAfter("frontend") {
365405
"""object Context {

0 commit comments

Comments
 (0)