File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -382,6 +382,12 @@ class TailRec extends MiniPhase {
382
382
case tree : Try =>
383
383
rewriteTry(tree)
384
384
385
+ case tree @ WhileDo (cond, body) =>
386
+ // we traverse the body and the condition for the purpose of reporting errors
387
+ noTailTransform(cond)
388
+ noTailTransform(body)
389
+ tree
390
+
385
391
case _ : Alternative | _ : Bind =>
386
392
assert(false , " We should never have gotten inside a pattern" )
387
393
tree
Original file line number Diff line number Diff line change
1
+ import annotation .tailrec
2
+
3
+ object WhileLoops {
4
+ def cond : Boolean = ???
5
+
6
+ @ tailrec def rec1 : Unit = { // error: tailrec not applicable
7
+ while (cond) {
8
+ rec1 // error: not in tail position
9
+ }
10
+ }
11
+
12
+ @ tailrec def rec2 : Boolean = { // error: tailrec not applicable
13
+ while (rec2) { } // error: not in tail position
14
+ true
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments