From f5304b389eacf2b7e38fbac047efbd7b786820af Mon Sep 17 00:00:00 2001 From: Gabi Volpe Date: Sun, 18 Jun 2017 16:39:05 +0200 Subject: [PATCH 1/2] Move "type argument must be fully defined" message to new error message scheme using WilcardOnTypeArgumentNotAllowedOnNew. --- .../reporting/diagnostic/ErrorMessageID.java | 1 + .../dotc/reporting/diagnostic/messages.scala | 33 +++++++++++++++++++ .../src/dotty/tools/dotc/typer/Typer.scala | 2 +- .../dotc/reporting/ErrorMessagesTests.scala | 18 ++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index 080b53e75f8b..893005ce96b6 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -91,6 +91,7 @@ public enum ErrorMessageID { AnonymousFunctionMissingParamTypeID, SuperCallsNotAllowedInlineID, ModifiersNotAllowedID, + WildcardOnTypeArgumentNotAllowedOnNewID ; public int errorNumber() { diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 76ee98087ff3..923befcf2f09 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -205,6 +205,39 @@ object messages { |${"val f: Seq[Int] => Option[List[Int]] = { case xs @ List(1, 2, 3) => Some(xs) }"} """ } + case class WildcardOnTypeArgumentNotAllowedOnNew()(implicit ctx: Context) + extends Message(WildcardOnTypeArgumentNotAllowedOnNewID) { + val kind = "syntax" + val msg = "type argument must be fully defined" + + val code1 = + """ + |object TyperDemo { + | class Team[A] + | val team = new Team[_] + |} + """.stripMargin + + val code2 = + """ + |object TyperDemo { + | class Team[A] + | val team = new Team[Int] + |} + """.stripMargin + + val explanation = + hl"""|Wildcard on arguments is not allowed when declaring a new type. + | + |Given the following example: + | + |$code1 + | + |You must complete all the type parameters, for instance: + | + |$code2 """ + } + // Type Errors ------------------------------------------------------------ // case class DuplicateBind(bind: untpd.Bind, tree: untpd.CaseDef)(implicit ctx: Context) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 378cd97cf7cd..38188db3b1a7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -479,7 +479,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit tpt1 match { case AppliedTypeTree(_, targs) => for (targ @ TypeBoundsTree(_, _) <- targs) - ctx.error("type argument must be fully defined", targ.pos) + ctx.error(WildcardOnTypeArgumentNotAllowedOnNew(), targ.pos) case _ => } diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index 7a7515604a5c..2c07738ca334 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -849,4 +849,22 @@ class ErrorMessagesTests extends ErrorMessagesTest { assertEquals("lazy", flags.toString) assertEquals("trait", sort) } + + @Test def wildcardOnTypeArgumentNotAllowedOnNew = + checkMessagesAfter("refchecks") { + """ + |object TyperDemo { + | class Team[A] + | val team = new Team[_] + |}""".stripMargin + } + .expect { (ictx, messages) => + implicit val ctx: Context = ictx + val defn = ictx.definitions + + assertMessageCount(1, messages) + val err :: Nil = messages + + assertEquals(err, WildcardOnTypeArgumentNotAllowedOnNew()) + } } From 5e2ec92b3d2f974c0c88543cb864e4e6ddc87076 Mon Sep 17 00:00:00 2001 From: Gabi Volpe Date: Mon, 19 Jun 2017 11:46:48 +0200 Subject: [PATCH 2/2] Comma added at the end of the definition of new ErrorMessageID. --- .../dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index 893005ce96b6..3af368b37b7a 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -91,7 +91,7 @@ public enum ErrorMessageID { AnonymousFunctionMissingParamTypeID, SuperCallsNotAllowedInlineID, ModifiersNotAllowedID, - WildcardOnTypeArgumentNotAllowedOnNewID + WildcardOnTypeArgumentNotAllowedOnNewID, ; public int errorNumber() {