Skip to content

Commit b76f92f

Browse files
nicolasstuckiWojciechMazur
authored andcommitted
Do not propagate @tailrec to exported methods
Fixes #19505 [Cherry-picked aad73c1]
1 parent 495c9eb commit b76f92f

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
@@ -1251,7 +1251,10 @@ class Namer { typer: Typer =>
12511251
newSymbol(cls, forwarderName, mbrFlags, mbrInfo, coord = span)
12521252

12531253
forwarder.info = avoidPrivateLeaks(forwarder)
1254-
forwarder.addAnnotations(sym.annotations.filterConserve(_.symbol != defn.BodyAnnot))
1254+
forwarder.addAnnotations(sym.annotations.filterConserve { annot =>
1255+
annot.symbol != defn.BodyAnnot
1256+
&& annot.symbol != defn.TailrecAnnot
1257+
})
12551258

12561259
if forwarder.isType then
12571260
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)