Skip to content

Commit 0e28030

Browse files
committed
Fix handling of && and || in TailRec
Apply.fun should not be transformed in tail position
1 parent 70f7fe8 commit 0e28030

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

0 commit comments

Comments
 (0)