Skip to content

Fix computation of class nesting level in inliner #15671

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 2 commits into from
Jul 14, 2022
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
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,15 @@ class Inliner(val call: tpd.Tree)(using Context):
assert(argss.isEmpty)
true

/** The number of enclosing classes of this class, plus one */
private def classNestingLevel(cls: Symbol) = cls.ownersIterator.count(_.isClass)

// Compute val-definitions for all this-proxies and append them to `bindingsBuf`
private def computeThisBindings() = {
// All needed this-proxies, paired-with and sorted-by nesting depth of
// the classes they represent (innermost first)
val sortedProxies = thisProxy.toList
.map((cls, proxy) => (cls.ownersIterator.length, proxy.symbol, cls))
.map((cls, proxy) => (classNestingLevel(cls), proxy.symbol, cls))
.sortBy(-_._1)

def outerSelect(prefix: Tree, prefixCls: Symbol, hops: Int, info: Type) =
Expand Down Expand Up @@ -303,7 +306,7 @@ class Inliner(val call: tpd.Tree)(using Context):
val pre = inlineCallPrefix match
case Super(qual, _) => qual
case pre => pre
val preLevel = inlinedMethod.owner.ownersIterator.length
val preLevel = classNestingLevel(inlinedMethod.owner)
if preLevel > level then outerSelect(pre, inlinedMethod.owner, preLevel - level, selfSym.info)
else pre

Expand Down
11 changes: 11 additions & 0 deletions tests/pos/i15666.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trait GetInt {
def value: Int // if we add inline here, the program compiles
}

class Newtype {
def f: Int = ???

val g = new GetInt {
inline def value: Int = f // has to be inline to crash
}
}