diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index dc864a3ec4d5..4febbb96e3fc 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -79,6 +79,7 @@ object Inliner { override def transform(t: Tree)(using Context) = t match { case Inlined(t, Nil, expr) if t.isEmpty => expr + case _ if t.isEmpty => t case _ => super.transform(t.withSpan(call.span)) } } diff --git a/tests/neg/inline-foreach.scala b/tests/neg/inline-foreach.scala new file mode 100644 index 000000000000..a52bdf977206 --- /dev/null +++ b/tests/neg/inline-foreach.scala @@ -0,0 +1,20 @@ +trait MyRange { + inline def foreach(inline f: Int => Unit): Unit +} + +transparent inline def MyRange(inline start: Int, inline end: Int): MyRange = new { + inline def foreach(inline f: Int => Unit) = // error: Implementation restriction + var i = start + val e = end + while (i < e) { + f(i) + i += 1 + } +} + +object App { + val count: Int = 4 + for (i <- MyRange(0, count)) { // error: Deferred inline method foreach in trait MyRange cannot be invoked + Console.println("Number: " + i) + } +}