Skip to content

Commit 09a1f56

Browse files
authored
Merge pull request #2443 from ennru/ennru_TypeDoesNotTakeParameters
Move 'Type does not take parameters' to error case class
2 parents 9aeb139 + 72bcedf commit 09a1f56

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
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
@@ -60,6 +60,7 @@ public enum ErrorMessageID {
6060
MethodDoesNotTakeParametersId,
6161
AmbiguousOverloadID,
6262
ReassignmentToValID,
63+
TypeDoesNotTakeParametersID,
6364
;
6465

6566
public int errorNumber() {

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import printing.Highlighting._
1919
import printing.Formatting
2020
import ErrorMessageID._
2121
import Denotations.SingleDenotation
22+
import dotty.tools.dotc.ast.Trees
2223
import dotty.tools.dotc.core.SymDenotations.SymDenotation
2324

2425
object messages {
@@ -1277,7 +1278,7 @@ object messages {
12771278
|$noParameters""".stripMargin
12781279

12791280
}
1280-
1281+
12811282
case class AmbiguousOverload(tree: tpd.Tree, alts: List[SingleDenotation], pt: Type)(
12821283
err: typer.ErrorReporting.Errors)(
12831284
implicit ctx: Context)
@@ -1296,7 +1297,7 @@ object messages {
12961297
|- adding a type ascription as in `${"instance.myMethod: String => Int"}`
12971298
|"""
12981299
}
1299-
1300+
13001301
case class ReassignmentToVal(name: Names.Name)(implicit ctx: Context)
13011302
extends Message(ReassignmentToValID) {
13021303
val kind = "Reference"
@@ -1310,4 +1311,19 @@ object messages {
13101311
| ${"var"} $name ${"="} ...
13111312
|""".stripMargin
13121313
}
1314+
1315+
case class TypeDoesNotTakeParameters(tpe: Types.Type, params: List[Trees.Tree[Trees.Untyped]])(implicit ctx: Context)
1316+
extends Message(TypeDoesNotTakeParametersID) {
1317+
val kind = "Reference"
1318+
val msg = hl"$tpe does not take type parameters"
1319+
1320+
private val ps =
1321+
if (params.size == 1) hl"a type parameter ${params.head}"
1322+
else hl"type parameters ${params.map(_.show).mkString(", ")}"
1323+
1324+
val explanation =
1325+
i"""You specified $ps for ${hl"$tpe"}, which is not
1326+
|declared to take any.
1327+
|"""
1328+
}
13131329
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10521052
val tpt1 = typed(tree.tpt, AnyTypeConstructorProto)(ctx.retractMode(Mode.Pattern))
10531053
val tparams = tpt1.tpe.typeParams
10541054
if (tparams.isEmpty) {
1055-
ctx.error(ex"${tpt1.tpe} does not take type parameters", tree.pos)
1055+
ctx.error(TypeDoesNotTakeParameters(tpt1.tpe, tree.args), tree.pos)
10561056
tpt1
10571057
}
10581058
else {

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class ErrorMessagesTests extends ErrorMessagesTest {
399399
assertEquals("Scope.foo(1)", tree.show)
400400
assertEquals("((a: Int)Unit)(Scope.foo)", methodPart.show)
401401
}
402-
402+
403403
@Test def ambiugousOverloadWithWildcard =
404404
checkMessagesAfter("frontend") {
405405
"""object Context {
@@ -440,4 +440,21 @@ class ErrorMessagesTests extends ErrorMessagesTest {
440440
val ReassignmentToVal(name) :: Nil = messages
441441
assertEquals("value", name.show)
442442
}
443+
444+
@Test def typeDoesNotTakeParameters =
445+
checkMessagesAfter("frontend") {
446+
"""
447+
|trait WithOutParams
448+
|class Extending extends WithOutParams[String]
449+
""".stripMargin
450+
}
451+
.expect { (ictx, messages) =>
452+
implicit val ctx: Context = ictx
453+
val defn = ictx.definitions
454+
455+
assertMessageCount(1, messages)
456+
val TypeDoesNotTakeParameters(tpe, params) :: Nil = messages
457+
assertEquals("WithOutParams", tpe.show)
458+
}
459+
443460
}

0 commit comments

Comments
 (0)