Skip to content

Commit 3242e86

Browse files
authored
Merge pull request #2779 from TheLambdaTeam/wildcard-on-type-argument-not-allowed
Move "type argument must be fully defined" message to case class scheme
2 parents 888744f + 5e2ec92 commit 3242e86

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public enum ErrorMessageID {
9191
AnonymousFunctionMissingParamTypeID,
9292
SuperCallsNotAllowedInlineID,
9393
ModifiersNotAllowedID,
94+
WildcardOnTypeArgumentNotAllowedOnNewID,
9495
;
9596

9697
public int errorNumber() {

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)