Skip to content

Commit c01ee13

Browse files
authored
Merge pull request #5185 from dotty-staging/tailrec-and-or
Fix handling of && and || in TailRec
2 parents 70f7fe8 + f96f42c commit c01ee13

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

compiler/src/dotty/tools/dotc/transform/TailRec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class TailRec extends MiniPhase {
276276
case tree@Apply(fun, args) =>
277277
val meth = fun.symbol
278278
if (meth == defn.Boolean_|| || meth == defn.Boolean_&&)
279-
tpd.cpy.Apply(tree)(fun, transform(args))
279+
tpd.cpy.Apply(tree)(noTailTransform(fun), transform(args))
280280
else
281281
rewriteApply(tree)
282282

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import annotation.tailrec
2+
3+
class Test {
4+
def cond: Boolean = ???
5+
6+
@tailrec final def tailCall1(x: Int): Boolean =
7+
if (x < 0) tailCall1(0)
8+
else tailCall1(x - 1) || cond // error
9+
10+
@tailrec final def tailCall2(x: Int): Boolean =
11+
if (x < 0) tailCall2(0)
12+
else tailCall2(x - 1) && cond // error
13+
14+
@tailrec final def tailCall3(x: Int): Boolean =
15+
if (x < 0) tailCall3(0)
16+
else cond || tailCall3(x - 1)
17+
18+
@tailrec final def tailCall4(x: Int): Boolean =
19+
if (x < 0) tailCall4(0)
20+
else cond && tailCall4(x - 1)
21+
}

0 commit comments

Comments
 (0)