aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-10-25 17:39:49 +0200
committerGitHub <noreply@github.com>2016-10-25 17:39:49 +0200
commit0cd907da01671c510025a610cea9ab117c8f1ae4 (patch)
treebb3a77b5bd70a8e1bfa1150f08326d6bbbe7f59d /src
parent40da850dfb5218131d0a8a0cdfd87bbe54569832 (diff)
parent6660729efd3d8d74db0614947d30b3b6c08484c0 (diff)
downloaddotty-0cd907da01671c510025a610cea9ab117c8f1ae4.tar.gz
dotty-0cd907da01671c510025a610cea9ab117c8f1ae4.tar.bz2
dotty-0cd907da01671c510025a610cea9ab117c8f1ae4.zip
Merge pull request #1624 from sebastianharko/master
Add error message for Parsers:1329
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/parsing/Parsers.scala2
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/messages.scala32
2 files changed, 33 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala
index 6adb7f010..8fc99f072 100644
--- a/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -1327,7 +1327,7 @@ object Parsers {
if (in.token == YIELD) { in.nextToken(); ForYield(enums, expr()) }
else if (in.token == DO) { in.nextToken(); ForDo(enums, expr()) }
else {
- if (!wrappedEnums) syntaxErrorOrIncomplete("`yield' or `do' expected")
+ if (!wrappedEnums) syntaxErrorOrIncomplete(YieldOrDoExpectedInForComprehension())
ForDo(enums, expr())
}
}
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index c4e84aaee..303ab0437 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -512,4 +512,36 @@ object messages {
|}""".stripMargin
}
+ case class YieldOrDoExpectedInForComprehension()(implicit ctx: Context) extends Message(19) {
+ val kind = "Syntax"
+ val msg = hl"${"yield"} or ${"do"} expected"
+
+ 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
+ |
+ |${"val numbers = for i <- 1 to 3 yield i"}
+ |
+ | instead of
+ |
+ |${"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 (i <- 1 to 3) println(i)"}
+ |
+ | can be written as
+ |
+ |${"for i <- 1 to 3 do println(i) // notice the 'do' keyword"}
+ |
+ |""".stripMargin
+ }
+
}