File tree 1 file changed +11
-14
lines changed
src/dotty/tools/dotc/reporting/diagnostic
1 file changed +11
-14
lines changed Original file line number Diff line number Diff line change @@ -515,34 +515,31 @@ object messages {
515
515
case class YieldOrDoExpectedInForComprehension ()(implicit ctx : Context ) extends Message (19 ) {
516
516
val kind = " Syntax"
517
517
val msg = hl " ${" yield" } or ${" do" } expected "
518
-
519
- val code1 = " val numbers = for i <- 1 to 3 yield i"
520
- val code2 = " val numbers = for (i <- 1 to 3) yield i"
521
- val code3 = " for (i <- 1 to 3) println(i)"
522
- val code4 = " for i <- 1 to 3 do println(i) // notice the 'do' keyword"
523
-
518
+
524
519
val explanation =
525
- hl """ When the enumerators in a for comprehension are not placed in parentheses or braces, a ${" do" } or ${" yield" } statement
526
- |is required after the enumerators section of the comprehension.
520
+ hl """ When the enumerators in a for comprehension are not placed in parentheses or
521
+ |braces, a ${" do" } or ${" yield" } statement is required after the enumerators section
522
+ |of the comprehension.
527
523
|
528
524
|You can save some keystrokes by omitting the parentheses and writing
529
525
|
530
- | $code1
526
+ | ${ " val numbers = for i <- 1 to 3 yield i " }
531
527
|
532
528
| instead of
533
529
|
534
- | $code2
530
+ | ${ " val numbers = for (i <- 1 to 3) yield i " }
535
531
|
536
532
|but the ${" yield" } keyword is still required.
537
533
|
538
- |For comprehensions that simply perform a side effect without yielding anything can also be written without parentheses
539
- |but a ${" do" } keyword has to be included. For example,
534
+ |For comprehensions that simply perform a side effect without yielding anything
535
+ |can also be written without parentheses but a ${" do" } keyword has to be included.
536
+ |For example,
540
537
|
541
- | $code3
538
+ | ${ " for (i <- 1 to 3) println(i) " }
542
539
|
543
540
| can be written as
544
541
|
545
- | $code4
542
+ | ${ " for i <- 1 to 3 do println(i) // notice the 'do' keyword " }
546
543
|
547
544
| """ .stripMargin
548
545
}
You can’t perform that action at this time.
0 commit comments