Skip to content

Commit 3247bf4

Browse files
authored
Merge pull request #1871 from jarrodj/master
Add error message for unbound wildcard type. Parsers.scala:664
2 parents 39c27b6 + 2fd8ea8 commit 3247bf4

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ object Parsers {
676676
val t = typ()
677677
findWildcardType(t) match {
678678
case Some(wildcardPos) =>
679-
syntaxError("unbound wildcard type", wildcardPos)
679+
syntaxError(UnboundWildcardType(), wildcardPos)
680680
scalaAny
681681
case None => t
682682
}

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,4 +923,47 @@ object messages {
923923
|"""
924924
}
925925

926+
case class UnboundWildcardType()(implicit ctx: Context) extends Message(35) {
927+
val kind = "Syntax"
928+
val msg = "Unbound wildcard type"
929+
val explanation =
930+
hl"""|The wildcard type syntax (`_`) was used where it could not be bound.
931+
|Replace `_` with a non-wildcard type. If the type doesn't matter,
932+
|try replacing `_` with ${"Any"}.
933+
|
934+
|Examples:
935+
|
936+
|- Parameter lists
937+
|
938+
| Instead of:
939+
| ${"def foo(x: _) = ..."}
940+
|
941+
| Use ${"Any"} if the type doesn't matter:
942+
| ${"def foo(x: Any) = ..."}
943+
|
944+
|- Type arguments
945+
|
946+
| Instead of:
947+
| ${"val foo = List[_](1, 2)"}
948+
|
949+
| Use:
950+
| ${"val foo = List[Int](1, 2)"}
951+
|
952+
|- Type bounds
953+
|
954+
| Instead of:
955+
| ${"def foo[T <: _](x: T) = ..."}
956+
|
957+
| Remove the bounds if the type doesn't matter:
958+
| ${"def foo[T](x: T) = ..."}
959+
|
960+
|- ${"val"} and ${"def"} types
961+
|
962+
| Instead of:
963+
| ${"val foo: _ = 3"}
964+
|
965+
| Use:
966+
| ${"val foo: Int = 3"}
967+
|"""
968+
}
926969
}

0 commit comments

Comments
 (0)