Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit de43ee1

Browse files
authoredAug 7, 2019
Merge pull request #7002 from dotty-staging/fix-do-while
Fix do/while error message and add tests
2 parents 921153f + 5dfe7d2 commit de43ee1

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed
 

‎compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ object Parsers {
13321332
case DO =>
13331333
in.errorOrMigrationWarning(
13341334
i"""`do <body> while <cond>' is no longer supported,
1335-
|use `while {<body> ; <cond>} do ()' instead.
1335+
|use `while ({<body> ; <cond>}) ()' instead.
13361336
|The statement can be rewritten automatically under -language:Scala2 -migration -rewrite.
13371337
""")
13381338
val start = in.skipToken()
@@ -1353,7 +1353,7 @@ object Parsers {
13531353
}
13541354
patch(source, cond.span.endPos, "}) ()")
13551355
}
1356-
WhileDo(Block(body :: Nil, cond), Literal(Constant(())))
1356+
WhileDo(Block(body, cond), Literal(Constant(())))
13571357
}
13581358
case TRY =>
13591359
val tryOffset = in.offset

‎tests/pos-scala2/doWhile.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Test {
2+
do {
3+
val x = 1
4+
println(x)
5+
} while {
6+
val x = "a"
7+
println(x)
8+
true
9+
}
10+
11+
do {
12+
val x = 1
13+
} while {
14+
val x = "a"
15+
true
16+
}
17+
18+
val x: Int = 3
19+
do {
20+
val x = ""
21+
} while (x == 2)
22+
23+
do (x == 3)
24+
while {
25+
val x = "a"
26+
true
27+
}
28+
29+
}

0 commit comments

Comments
 (0)
Please sign in to comment.