aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
diff options
context:
space:
mode:
authorSebastian Harko <sebastian.harko@lightbend.com>2016-10-24 22:52:14 -0700
committerSebastian Harko <sebastian.harko@lightbend.com>2016-10-24 22:52:14 -0700
commitef0d2913a628e3ce06bc81942dc236170aa744c1 (patch)
tree10b98822f12aeb2f7da1d62c76b7f7b5924f0053 /src/dotty/tools/dotc/reporting/diagnostic/messages.scala
parent56731e4b18728427f0b7188eb91afc475b36bb18 (diff)
downloaddotty-ef0d2913a628e3ce06bc81942dc236170aa744c1.tar.gz
dotty-ef0d2913a628e3ce06bc81942dc236170aa744c1.tar.bz2
dotty-ef0d2913a628e3ce06bc81942dc236170aa744c1.zip
add error message related to missing yield/do in for-comprehensions
Diffstat (limited to 'src/dotty/tools/dotc/reporting/diagnostic/messages.scala')
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/messages.scala35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index c4e84aaee..264479467 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -512,4 +512,39 @@ object messages {
|}""".stripMargin
}
+ case class YieldOrDoExpectedInForComprehension()(implicit ctx: Context) extends Message(19) {
+ val kind = "Syntax"
+ val msg = hl"${"yield"} or ${"do"} expected"
+
+ val code1 = "val numbers = for i <- 1 to 3 yield i"
+ val code2 = "val numbers = for (i <- 1 to 3) yield i"
+ val code3 = "for (i <- 1 to 3) println(i)"
+ val code4 = "for i <- 1 to 3 do println(i) // notice the 'do' keyword"
+
+ val explanation =
+ hl"""When the enumerators in a for comprehension are not placed in parentheses or braces, a ${"do"} or ${"yield"} statement
+ |is required after the enumerators section of the comprehension.
+ |
+ |You can save some keystrokes by omitting the parentheses and writing
+ |
+ |$code1
+ |
+ | instead of
+ |
+ |$code2
+ |
+ |but the ${"yield"} keyword is still required.
+ |
+ |For comprehensions that simply perform a side effect without yielding anything can also be written without parentheses
+ |but a ${"do"} keyword has to be included. For example,
+ |
+ |$code3
+ |
+ | can be written as
+ |
+ |$code4
+ |
+ |""".stripMargin
+ }
+
}