Skip to content

Commit 4a51412

Browse files
authored
Merge pull request #7971 from jvdp/1589-checking
Message class for missing type parameter in type application
2 parents 0f0d25c + 92c12df commit 4a51412

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
148148
IllegalSuperAccessorID,
149149
TraitParameterUsedAsParentPrefixID,
150150
UnknownNamedEnclosingClassOrObjectID,
151-
IllegalCyclicTypeReferenceID
151+
IllegalCyclicTypeReferenceID,
152+
MissingTypeParameterInTypeAppID
152153

153154
def errorNumber = ordinal - 2
154155
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,15 @@ object messages {
14571457
val explanation: String = ""
14581458
}
14591459

1460+
case class MissingTypeParameterInTypeApp(tpe: Type)(implicit ctx: Context)
1461+
extends Message(MissingTypeParameterInTypeAppID) {
1462+
val numParams = tpe.typeParams.length
1463+
val parameters = if (numParams == 1) "parameter" else "parameters"
1464+
val msg: String = em"Missing type $parameters for $tpe"
1465+
val kind: String = "Type Mismatch"
1466+
val explanation: String = em"A fully applied type is expected but $tpe takes $numParams $parameters."
1467+
}
1468+
14601469
case class DoesNotConformToBound(tpe: Type, which: String, bound: Type)(
14611470
err: Errors)(implicit ctx: Context)
14621471
extends Message(DoesNotConformToBoundID) {

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ object Checking {
5050
def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type, app: Type = NoType)(implicit ctx: Context): Unit = {
5151
args.lazyZip(boundss).foreach { (arg, bound) =>
5252
if (!bound.isLambdaSub && !arg.tpe.hasSimpleKind)
53-
// see MissingTypeParameterFor
54-
ctx.error(ex"missing type parameter(s) for $arg", arg.sourcePos)
53+
errorTree(arg, MissingTypeParameterInTypeApp(arg.tpe))
5554
}
5655
for ((arg, which, bound) <- ctx.boundsViolations(args, boundss, instantiate, app))
5756
ctx.error(

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

+15
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,21 @@ class ErrorMessagesTests extends ErrorMessagesTest {
636636
assertEquals("List", tpe.show)
637637
}
638638

639+
@Test def missingTypeParameterInTypeApp =
640+
checkMessagesAfter(RefChecks.name) {
641+
"""object Scope {
642+
| def f[T] = ???
643+
| val x = f[List]
644+
| val y = f[Either]
645+
|}""".stripMargin
646+
}
647+
.expect { (ictx, messages) =>
648+
implicit val ctx: Context = ictx
649+
assertMessageCount(2, messages)
650+
assertEquals("Missing type parameter for List", messages(1).msg)
651+
assertEquals("Missing type parameters for Either", messages(0).msg)
652+
}
653+
639654
@Test def doesNotConformToBound =
640655
checkMessagesAfter(RefChecks.name) {
641656
"""class WithParam[A <: List[Int]]

tests/neg/kinds2.check

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
-- Error: tests/neg/kinds2.scala:14:4 ----------------------------------------------------------------------------------
1+
-- [E141] Type Mismatch Error: tests/neg/kinds2.scala:14:4 -------------------------------------------------------------
22
14 | f[C] // error: missing type parameter(s)
33
| ^
4-
| missing type parameter(s) for C
4+
| Missing type parameter for Test.C
5+
6+
longer explanation available when compiling with `-explain`

0 commit comments

Comments
 (0)