File tree 4 files changed +16
-9
lines changed
compiler/src/dotty/tools/dotc/transform 4 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -435,12 +435,15 @@ class TailRec extends MiniPhase {
435
435
436
436
case tree : DefDef =>
437
437
if (isMandatory)
438
- // We cant tail recurse through nested definitions, so dont want to propagate to child nodes
439
- // We dont want to fail if there is a call that would recurse (as this would be a non self recurse), so dont
440
- // want to call noTailTransform
441
- // We can however warn in this case, as its likely in this situation that someone would expect a tail
442
- // recursion optimization and enabling this to optimise would be a simple case of inlining the inner method
443
- new NestedTailRecAlerter (method, tree.symbol).traverse(tree)
438
+ if (tree.symbol.is(Synthetic ))
439
+ noTailTransform(tree.rhs)
440
+ else
441
+ // We cant tail recurse through nested definitions, so dont want to propagate to child nodes
442
+ // We dont want to fail if there is a call that would recurse (as this would be a non self recurse), so dont
443
+ // want to call noTailTransform
444
+ // We can however warn in this case, as its likely in this situation that someone would expect a tail
445
+ // recursion optimization and enabling this to optimise would be a simple case of inlining the inner method
446
+ new NestedTailRecAlerter (method, tree.symbol).traverse(tree)
444
447
tree
445
448
446
449
case _ : Super | _ : This | _ : Literal | _ : TypeTree | _ : TypeDef | EmptyTree =>
Original file line number Diff line number Diff line change
1
+ import scala .annotation .tailrec
1
2
@ tailrec
2
- def foo (): Unit =
3
+ def foo (): Unit = // error
3
4
def bar (): Unit =
4
5
if (??? )
5
6
foo()
Original file line number Diff line number Diff line change @@ -16,8 +16,10 @@ object Test {
16
16
rec3 // error: not in tail position
17
17
})
18
18
19
- @ tailrec def rec4 : Unit = {
20
- def local = rec4 // error: not in tail position
19
+ // This is technically not breaching tail recursion as rec4 does not call itself, local does
20
+ // This instead fails due to having no tail recursion at all
21
+ @ tailrec def rec4 : Unit = { // error: no recursive calls
22
+ def local = rec4
21
23
}
22
24
23
25
@ tailrec def rec5 : Int = {
Original file line number Diff line number Diff line change
1
+ import scala .annotation .tailrec
1
2
@ tailrec
2
3
def foo (): Unit =
3
4
def bar (): Unit =
You can’t perform that action at this time.
0 commit comments