File tree Expand file tree Collapse file tree 4 files changed +53
-1
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ public enum ErrorMessageID {
9191 AnonymousFunctionMissingParamTypeID ,
9292 SuperCallsNotAllowedInlineID ,
9393 ModifiersNotAllowedID ,
94+ WildcardOnTypeArgumentNotAllowedOnNewID ,
9495 ;
9596
9697 public int errorNumber () {
Original file line number Diff line number Diff line change @@ -205,6 +205,39 @@ object messages {
205205 | ${" val f: Seq[Int] => Option[List[Int]] = { case xs @ List(1, 2, 3) => Some(xs) }" } """
206206 }
207207
208+ case class WildcardOnTypeArgumentNotAllowedOnNew ()(implicit ctx : Context )
209+ extends Message (WildcardOnTypeArgumentNotAllowedOnNewID ) {
210+ val kind = " syntax"
211+ val msg = " type argument must be fully defined"
212+
213+ val code1 =
214+ """
215+ |object TyperDemo {
216+ | class Team[A]
217+ | val team = new Team[_]
218+ |}
219+ """ .stripMargin
220+
221+ val code2 =
222+ """
223+ |object TyperDemo {
224+ | class Team[A]
225+ | val team = new Team[Int]
226+ |}
227+ """ .stripMargin
228+
229+ val explanation =
230+ hl """ |Wildcard on arguments is not allowed when declaring a new type.
231+ |
232+ |Given the following example:
233+ |
234+ | $code1
235+ |
236+ |You must complete all the type parameters, for instance:
237+ |
238+ | $code2 """
239+ }
240+
208241
209242 // Type Errors ------------------------------------------------------------ //
210243 case class DuplicateBind (bind : untpd.Bind , tree : untpd.CaseDef )(implicit ctx : Context )
Original file line number Diff line number Diff line change @@ -479,7 +479,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
479479 tpt1 match {
480480 case AppliedTypeTree (_, targs) =>
481481 for (targ @ TypeBoundsTree (_, _) <- targs)
482- ctx.error(" type argument must be fully defined " , targ.pos)
482+ ctx.error(WildcardOnTypeArgumentNotAllowedOnNew () , targ.pos)
483483 case _ =>
484484 }
485485
Original file line number Diff line number Diff line change @@ -849,4 +849,22 @@ class ErrorMessagesTests extends ErrorMessagesTest {
849849 assertEquals(" lazy" , flags.toString)
850850 assertEquals(" trait" , sort)
851851 }
852+
853+ @ Test def wildcardOnTypeArgumentNotAllowedOnNew =
854+ checkMessagesAfter(" refchecks" ) {
855+ """
856+ |object TyperDemo {
857+ | class Team[A]
858+ | val team = new Team[_]
859+ |}""" .stripMargin
860+ }
861+ .expect { (ictx, messages) =>
862+ implicit val ctx : Context = ictx
863+ val defn = ictx.definitions
864+
865+ assertMessageCount(1 , messages)
866+ val err :: Nil = messages
867+
868+ assertEquals(err, WildcardOnTypeArgumentNotAllowedOnNew ())
869+ }
852870}
You can’t perform that action at this time.
0 commit comments