Skip to content

Add error message for unbound wildcard type. Parsers.scala:664 #1871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ object Parsers {
val t = typ()
findWildcardType(t) match {
case Some(wildcardPos) =>
syntaxError("unbound wildcard type", wildcardPos)
syntaxError(UnboundWildcardType(), wildcardPos)
scalaAny
case None => t
}
Expand Down
43 changes: 43 additions & 0 deletions compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -923,4 +923,47 @@ object messages {
|"""
}

case class UnboundWildcardType()(implicit ctx: Context) extends Message(35) {
val kind = "Syntax"
val msg = "Unbound wildcard type"
val explanation =
hl"""|The wildcard type syntax (`_`) was used where it could not be bound.
|Replace `_` with a non-wildcard type. If the type doesn't matter,
|try replacing `_` with ${"Any"}.
|
|Examples:
|
|- Parameter lists
|
| Instead of:
| ${"def foo(x: _) = ..."}
|
| Use ${"Any"} if the type doesn't matter:
| ${"def foo(x: Any) = ..."}
|
|- Type arguments
|
| Instead of:
| ${"val foo = List[_](1, 2)"}
|
| Use:
| ${"val foo = List[Int](1, 2)"}
|
|- Type bounds
|
| Instead of:
| ${"def foo[T <: _](x: T) = ..."}
|
| Remove the bounds if the type doesn't matter:
| ${"def foo[T](x: T) = ..."}
|
|- ${"val"} and ${"def"} types
|
| Instead of:
| ${"val foo: _ = 3"}
|
| Use:
| ${"val foo: Int = 3"}
|"""
}
}