Skip to content

Move 'Type does not take parameters' to error case class #2443

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
May 16, 2017
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 @@ -60,6 +60,7 @@ public enum ErrorMessageID {
MethodDoesNotTakeParametersId,
AmbiguousOverloadID,
ReassignmentToValID,
TypeDoesNotTakeParametersID,
;

public int errorNumber() {
Expand Down
20 changes: 18 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import printing.Highlighting._
import printing.Formatting
import ErrorMessageID._
import Denotations.SingleDenotation
import dotty.tools.dotc.ast.Trees
import dotty.tools.dotc.core.SymDenotations.SymDenotation

object messages {
Expand Down Expand Up @@ -1277,7 +1278,7 @@ object messages {
|$noParameters""".stripMargin

}

case class AmbiguousOverload(tree: tpd.Tree, alts: List[SingleDenotation], pt: Type)(
err: typer.ErrorReporting.Errors)(
implicit ctx: Context)
Expand All @@ -1296,7 +1297,7 @@ object messages {
|- adding a type ascription as in `${"instance.myMethod: String => Int"}`
|"""
}

case class ReassignmentToVal(name: Names.Name)(implicit ctx: Context)
extends Message(ReassignmentToValID) {
val kind = "Reference"
Expand All @@ -1310,4 +1311,19 @@ object messages {
| ${"var"} $name ${"="} ...
|""".stripMargin
}

case class TypeDoesNotTakeParameters(tpe: Types.Type, params: List[Trees.Tree[Trees.Untyped]])(implicit ctx: Context)
extends Message(TypeDoesNotTakeParametersID) {
val kind = "Reference"
val msg = hl"$tpe does not take type parameters"

private val ps =
if (params.size == 1) hl"a type parameter ${params.head}"
else hl"type parameters ${params.map(_.show).mkString(", ")}"

val explanation =
i"""You specified $ps for ${hl"$tpe"}, which is not
|declared to take any.
|"""
}
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val tpt1 = typed(tree.tpt, AnyTypeConstructorProto)(ctx.retractMode(Mode.Pattern))
val tparams = tpt1.tpe.typeParams
if (tparams.isEmpty) {
ctx.error(ex"${tpt1.tpe} does not take type parameters", tree.pos)
ctx.error(TypeDoesNotTakeParameters(tpt1.tpe, tree.args), tree.pos)
tpt1
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class ErrorMessagesTests extends ErrorMessagesTest {
assertEquals("Scope.foo(1)", tree.show)
assertEquals("((a: Int)Unit)(Scope.foo)", methodPart.show)
}

@Test def ambiugousOverloadWithWildcard =
checkMessagesAfter("frontend") {
"""object Context {
Expand Down Expand Up @@ -440,4 +440,21 @@ class ErrorMessagesTests extends ErrorMessagesTest {
val ReassignmentToVal(name) :: Nil = messages
assertEquals("value", name.show)
}

@Test def typeDoesNotTakeParameters =
checkMessagesAfter("frontend") {
"""
|trait WithOutParams
|class Extending extends WithOutParams[String]
""".stripMargin
}
.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
val defn = ictx.definitions

assertMessageCount(1, messages)
val TypeDoesNotTakeParameters(tpe, params) :: Nil = messages
assertEquals("WithOutParams", tpe.show)
}

}