aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorJarrod Janssen <jrodjanssen@gmail.com>2017-01-02 15:09:53 -0600
committerJarrod Janssen <jrodjanssen@gmail.com>2017-01-02 15:56:11 -0600
commit2fd8ea88e7f732482afa795eab0a74be5cc36663 (patch)
treebf13d6210f57526d11bc170f40fdf7994e88fe7f /compiler
parent39c27b6a8aaa2c7303db54011082246ada06c0a0 (diff)
downloaddotty-2fd8ea88e7f732482afa795eab0a74be5cc36663.tar.gz
dotty-2fd8ea88e7f732482afa795eab0a74be5cc36663.tar.bz2
dotty-2fd8ea88e7f732482afa795eab0a74be5cc36663.zip
Add error message for unbound wildcard type.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/src/dotty/tools/dotc/parsing/Parsers.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala43
2 files changed, 44 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
index 1e8fb9d26..18f0b42f5 100644
--- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -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
}
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index b55b7e868..25db28e4a 100644
--- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -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"}
+ |"""
+ }
}