aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorruben <rubnepieters@gmail.com>2016-10-21 07:43:44 +0200
committerruben <rubnepieters@gmail.com>2016-10-22 08:38:12 +0200
commitbf80147465dd0d7b1de47eb2f980380624b008db (patch)
tree64741a05ba5d7d93e53598c2d6a6c6095c07208c /src
parenta6d3723d18a554e630a6859bfc6f213f21e3d6cf (diff)
downloaddotty-bf80147465dd0d7b1de47eb2f980380624b008db.tar.gz
dotty-bf80147465dd0d7b1de47eb2f980380624b008db.tar.bz2
dotty-bf80147465dd0d7b1de47eb2f980380624b008db.zip
Add unbound placeholder parameter message.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/parsing/Parsers.scala2
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/messages.scala35
2 files changed, 36 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala
index 292e410f5..80c8f7b15 100644
--- a/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -334,7 +334,7 @@ object Parsers {
try op
finally {
placeholderParams match {
- case vd :: _ => syntaxError("unbound placeholder parameter", vd.pos)
+ case vd :: _ => syntaxError(UnboundPlaceholderParameter(), vd.pos)
case _ =>
}
placeholderParams = savedPlaceholderParams
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index c05110b66..ce60d053a 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -447,4 +447,39 @@ object messages {
}
+ case class UnboundPlaceholderParameter()(implicit ctx:Context)
+ extends Message(16) {
+ val kind = "Syntax"
+
+ val msg = hl"unbound placeholder parameter; incorrect use of `_`"
+
+ val explanation =
+ hl"""The `_` placeholder syntax was used where it could not be bound.
+ |Consider explicitly writing the variable binding.
+ |
+ |This can be done by replacing `_` with a variable (eg. `x`)
+ |and adding ${"x =>"} where applicable.
+ |
+ |Example before:
+ |
+ |${"{ _ }"}
+ |
+ |Example after:
+ |
+ |${"x => { x }"}
+ |
+ |Another common occurrence for this error is defining a val with `_`:
+ |
+ |${"val a = _"}
+ |
+ |But this val definition isn't very useful, it can never be assigned
+ |another value. And thus will always remain uninitialized.
+ |Consider replacing the ${"val"} with ${"var"}:
+ |
+ |${"var a = _"}
+ |
+ |Note that this use of `_` is not placeholder syntax,
+ |but an uninitialized var definition
+ """.stripMargin
+ }
}