Skip to content

Commit a2ec0d6

Browse files
Merge pull request #12061 from dotty-staging/fix-#10970
Disallow `@tailrec inline`
2 parents 85a03ee + aac8d7e commit a2ec0d6

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,11 @@ object Checking {
467467
if (sym.is(Trait) && sym.is(Final))
468468
fail(TraitsMayNotBeFinal(sym))
469469
// Skip ModuleVal since the annotation will also be on the ModuleClass
470-
if (sym.hasAnnotation(defn.TailrecAnnot) && !sym.isOneOf(Method | ModuleVal))
471-
fail(TailrecNotApplicable(sym))
470+
if sym.hasAnnotation(defn.TailrecAnnot) then
471+
if !sym.isOneOf(Method | ModuleVal) then
472+
fail(TailrecNotApplicable(sym))
473+
else if sym.is(Inline) then
474+
fail("Inline methods cannot be @tailrec")
472475
if (sym.hasAnnotation(defn.NativeAnnot)) {
473476
if (!sym.is(Deferred))
474477
fail(NativeMembersMayNotHaveImplementation(sym))

tests/neg/i10970.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import scala.annotation.tailrec
2+
3+
@tailrec inline def foo() = ??? // error

0 commit comments

Comments
 (0)