Skip to content

Message class for missing type parameter in type application #7971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
IllegalSuperAccessorID,
TraitParameterUsedAsParentPrefixID,
UnknownNamedEnclosingClassOrObjectID,
IllegalCyclicTypeReferenceID
IllegalCyclicTypeReferenceID,
MissingTypeParameterInTypeAppID

def errorNumber = ordinal - 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,15 @@ object messages {
val explanation: String = ""
}

case class MissingTypeParameterInTypeApp(tpe: Type)(implicit ctx: Context)
extends Message(MissingTypeParameterInTypeAppID) {
val numParams = tpe.typeParams.length
val parameters = if (numParams == 1) "parameter" else "parameters"
val msg: String = em"Missing type $parameters for $tpe"
val kind: String = "Type Mismatch"
val explanation: String = em"A fully applied type is expected but $tpe takes $numParams $parameters."
}

case class DoesNotConformToBound(tpe: Type, which: String, bound: Type)(
err: Errors)(implicit ctx: Context)
extends Message(DoesNotConformToBoundID) {
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ object Checking {
def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type, app: Type = NoType)(implicit ctx: Context): Unit = {
args.lazyZip(boundss).foreach { (arg, bound) =>
if (!bound.isLambdaSub && !arg.tpe.hasSimpleKind)
// see MissingTypeParameterFor
ctx.error(ex"missing type parameter(s) for $arg", arg.sourcePos)
errorTree(arg, MissingTypeParameterInTypeApp(arg.tpe))
}
for ((arg, which, bound) <- ctx.boundsViolations(args, boundss, instantiate, app))
ctx.error(
Expand Down
15 changes: 15 additions & 0 deletions compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,21 @@ class ErrorMessagesTests extends ErrorMessagesTest {
assertEquals("List", tpe.show)
}

@Test def missingTypeParameterInTypeApp =
checkMessagesAfter(RefChecks.name) {
"""object Scope {
| def f[T] = ???
| val x = f[List]
| val y = f[Either]
|}""".stripMargin
}
.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
assertMessageCount(2, messages)
assertEquals("Missing type parameter for List", messages(1).msg)
assertEquals("Missing type parameters for Either", messages(0).msg)
}

@Test def doesNotConformToBound =
checkMessagesAfter(RefChecks.name) {
"""class WithParam[A <: List[Int]]
Expand Down
6 changes: 4 additions & 2 deletions tests/neg/kinds2.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-- Error: tests/neg/kinds2.scala:14:4 ----------------------------------------------------------------------------------
-- [E141] Type Mismatch Error: tests/neg/kinds2.scala:14:4 -------------------------------------------------------------
14 | f[C] // error: missing type parameter(s)
| ^
| missing type parameter(s) for C
| Missing type parameter for Test.C

longer explanation available when compiling with `-explain`