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 {
91
91
AnonymousFunctionMissingParamTypeID ,
92
92
SuperCallsNotAllowedInlineID ,
93
93
ModifiersNotAllowedID ,
94
+ WildcardOnTypeArgumentNotAllowedOnNewID ,
94
95
;
95
96
96
97
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -205,6 +205,39 @@ object messages {
205
205
| ${" val f: Seq[Int] => Option[List[Int]] = { case xs @ List(1, 2, 3) => Some(xs) }" } """
206
206
}
207
207
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
+
208
241
209
242
// Type Errors ------------------------------------------------------------ //
210
243
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
479
479
tpt1 match {
480
480
case AppliedTypeTree (_, targs) =>
481
481
for (targ @ TypeBoundsTree (_, _) <- targs)
482
- ctx.error(" type argument must be fully defined " , targ.pos)
482
+ ctx.error(WildcardOnTypeArgumentNotAllowedOnNew () , targ.pos)
483
483
case _ =>
484
484
}
485
485
Original file line number Diff line number Diff line change @@ -849,4 +849,22 @@ class ErrorMessagesTests extends ErrorMessagesTest {
849
849
assertEquals(" lazy" , flags.toString)
850
850
assertEquals(" trait" , sort)
851
851
}
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
+ }
852
870
}
You can’t perform that action at this time.
0 commit comments