Skip to content

Commit aad73c1

Browse files
committed
Do not propagate @tailrec to exported methods
Fixes #19505
1 parent 30bdc33 commit aad73c1

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,10 @@ class Namer { typer: Typer =>
12541254
newSymbol(cls, forwarderName, mbrFlags, mbrInfo, coord = span)
12551255

12561256
forwarder.info = avoidPrivateLeaks(forwarder)
1257-
forwarder.addAnnotations(sym.annotations.filterConserve(_.symbol != defn.BodyAnnot))
1257+
forwarder.addAnnotations(sym.annotations.filterConserve { annot =>
1258+
annot.symbol != defn.BodyAnnot
1259+
&& annot.symbol != defn.TailrecAnnot
1260+
})
12581261

12591262
if forwarder.isType then
12601263
buf += tpd.TypeDef(forwarder.asType).withSpan(span)

tests/pos/i19505.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import scala.annotation.tailrec
2+
3+
object Foo:
4+
@tailrec
5+
def foo(n: Int): Int =
6+
if n == 0 then 0
7+
else foo(n-1)
8+
9+
object Bar:
10+
export Foo.foo // def foo here should not have `@tailrec`

tests/warn/i19505.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.annotation.tailrec
2+
3+
object Foo:
4+
@tailrec
5+
def foo: Int = foo // warn: Infinite recursive call
6+
7+
object Bar:
8+
export Foo.foo // def foo here should not have `@tailrec`

0 commit comments

Comments
 (0)