diff options
-rw-r--r-- | src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 264479467..303ab0437 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -515,34 +515,31 @@ object messages { 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. + 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 + |${"val numbers = for i <- 1 to 3 yield i"} | | instead of | - |$code2 + |${"val numbers = for (i <- 1 to 3) yield i"} | |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, + |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 + |${"for (i <- 1 to 3) println(i)"} | | can be written as | - |$code4 + |${"for i <- 1 to 3 do println(i) // notice the 'do' keyword"} | |""".stripMargin } |