diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 973df2e5756c..20db108bbb28 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -1487,7 +1487,10 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { override def hasInliningErrors(using Context) = ctx.reporter.errorCount > initialErrorCount private def inlineIfNeeded(tree: Tree)(using Context): Tree = - if Inliner.needsInlining(tree) then Inliner.inlineCall(tree) + val meth = tree.symbol + if meth.isAllOf(DeferredInline) then + errorTree(tree, i"Deferred inline ${meth.showLocated} cannot be invoked") + else if Inliner.needsInlining(tree) then Inliner.inlineCall(tree) else tree override def typedUnadapted(tree: untpd.Tree, pt: Type, locked: TypeVars)(using Context): Tree = diff --git a/tests/neg/i12555.scala b/tests/neg/i12555.scala new file mode 100644 index 000000000000..3a5996159e10 --- /dev/null +++ b/tests/neg/i12555.scala @@ -0,0 +1,6 @@ +trait Noop { + inline def noop: String +} + +inline def boom: String = (??? : Noop).noop +def test: Unit = boom // error diff --git a/tests/neg/i12555b.scala b/tests/neg/i12555b.scala new file mode 100644 index 000000000000..5931bda4ba27 --- /dev/null +++ b/tests/neg/i12555b.scala @@ -0,0 +1,18 @@ +trait Noop[T]: + //note: making this "not inline" fixes the result + inline def noop(fa: T): T + +object Noop { + inline def noop[T](alg: T)(using n: Noop[T]): T = n.noop(alg) +} + +import Noop.* + +final case class User(name: String, age: Int) + +inline given Noop[User] = a => a + +val u = User("hello", 45) + +@main +def run = println(Noop.noop(u)) // error diff --git a/tests/neg/i12555c.scala b/tests/neg/i12555c.scala new file mode 100644 index 000000000000..9d2a10aff4c9 --- /dev/null +++ b/tests/neg/i12555c.scala @@ -0,0 +1,4 @@ +trait Noop { + inline def noop: String +} +def test2: Unit = (??? : Noop).noop // error