Skip to content

Count references correctly when dropping unused defs #5646

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

Merged
merged 1 commit into from
Jan 2, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -954,13 +954,18 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
override def traverse(t: Tree)(implicit ctx: Context) = {
def updateRefCount(sym: Symbol, inc: Int) =
for (x <- refCount.get(sym)) refCount(sym) = x + inc
def updateTermRefCounts(t: Tree) =
t.typeOpt.foreachPart {
case ref: TermRef => updateRefCount(ref.symbol, 2) // can't be inlined, so make sure refCount is at least 2
case _ =>
}

t match {
case t: RefTree => updateRefCount(t.symbol, 1)
case t: RefTree =>
updateRefCount(t.symbol, 1)
updateTermRefCounts(t)
case _: New | _: TypeTree =>
t.typeOpt.foreachPart {
case ref: TermRef => updateRefCount(ref.symbol, 2) // can't be inlined, so make sure refCount is at least 2
case _ =>
}
updateTermRefCounts(t)
case _ =>
}
traverseChildren(t)
Expand Down
14 changes: 14 additions & 0 deletions tests/pos/i5572.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
trait Foo {
type Id[t] = t
inline def foo[T](t: T) <: Id[T] =
inline t match {
case i: Int => (i+1).asInstanceOf[Id[T]]
case _ => t
}
}

object Bar extends Foo

object Test {
Bar.foo(23)
}