Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect abstract inline method calls after inlining #12777

Merged
merged 1 commit into from Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Expand Up @@ -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 =
Expand Down
6 changes: 6 additions & 0 deletions 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
18 changes: 18 additions & 0 deletions 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
4 changes: 4 additions & 0 deletions tests/neg/i12555c.scala
@@ -0,0 +1,4 @@
trait Noop {
inline def noop: String
}
def test2: Unit = (??? : Noop).noop // error