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 @@ -438,12 +438,15 @@ class TailRec extends MiniPhase {
438
438
439
439
case tree : DefDef =>
440
440
if (isMandatory)
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)
441
+ if (tree.symbol.is(Synthetic ))
442
+ noTailTransform(tree.rhs)
443
+ else
444
+ // We cant tail recurse through nested definitions, so dont want to propagate to child nodes
445
+ // We dont want to fail if there is a call that would recurse (as this would be a non self recurse), so dont
446
+ // want to call noTailTransform
447
+ // We can however warn in this case, as its likely in this situation that someone would expect a tail
448
+ // recursion optimization and enabling this to optimise would be a simple case of inlining the inner method
449
+ new NestedTailRecAlerter (method, tree.symbol).traverse(tree)
447
450
tree
448
451
449
452
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