From aac8d7e15307dc25313c79c2999f80b5e2098d8c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 12 Apr 2021 14:17:50 +0200 Subject: [PATCH] Disallow `@tailrec inline` Fixes #10970 --- compiler/src/dotty/tools/dotc/typer/Checking.scala | 7 +++++-- tests/neg/i10970.scala | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i10970.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 9f48913d1f67..e6eb0f99c600 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -467,8 +467,11 @@ object Checking { if (sym.is(Trait) && sym.is(Final)) fail(TraitsMayNotBeFinal(sym)) // Skip ModuleVal since the annotation will also be on the ModuleClass - if (sym.hasAnnotation(defn.TailrecAnnot) && !sym.isOneOf(Method | ModuleVal)) - fail(TailrecNotApplicable(sym)) + if sym.hasAnnotation(defn.TailrecAnnot) then + if !sym.isOneOf(Method | ModuleVal) then + fail(TailrecNotApplicable(sym)) + else if sym.is(Inline) then + fail("Inline methods cannot be @tailrec") if (sym.hasAnnotation(defn.NativeAnnot)) { if (!sym.is(Deferred)) fail(NativeMembersMayNotHaveImplementation(sym)) diff --git a/tests/neg/i10970.scala b/tests/neg/i10970.scala new file mode 100644 index 000000000000..ae91e472630c --- /dev/null +++ b/tests/neg/i10970.scala @@ -0,0 +1,3 @@ +import scala.annotation.tailrec + +@tailrec inline def foo() = ??? // error