Skip to content

Commit

Permalink
Fix computation of class nesting level in inliner
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jul 13, 2022
1 parent 79d9a6f commit a9527bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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 nestingLevel(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) => (nestingLevel(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 = nestingLevel(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
}
}

0 comments on commit a9527bf

Please sign in to comment.