Skip to content

Commit 8e43405

Browse files
authored
Merge pull request #15755 from dotty-staging/backport-15671
Backport #15671: Fix computation of class nesting level in inliner
2 parents 86aa1e4 + f013bbf commit 8e43405

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,12 +613,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
613613
assert(argss.isEmpty)
614614
true
615615

616+
/** The number of enclosing classes of this class, plus one */
617+
private def classNestingLevel(cls: Symbol) = cls.ownersIterator.count(_.isClass)
618+
616619
// Compute val-definitions for all this-proxies and append them to `bindingsBuf`
617620
private def computeThisBindings() = {
618621
// All needed this-proxies, paired-with and sorted-by nesting depth of
619622
// the classes they represent (innermost first)
620623
val sortedProxies = thisProxy.toList
621-
.map((cls, proxy) => (cls.ownersIterator.length, proxy.symbol))
624+
.map((cls, proxy) => (classNestingLevel(cls), proxy.symbol))
622625
.sortBy(-_._1)
623626

624627
var lastSelf: Symbol = NoSymbol
@@ -640,7 +643,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
640643
val pre = inlineCallPrefix match
641644
case Super(qual, _) => qual
642645
case pre => pre
643-
val preLevel = inlinedMethod.owner.ownersIterator.length
646+
val preLevel = classNestingLevel(inlinedMethod.owner)
644647
if preLevel > level then pre.outerSelect(preLevel - level, selfSym.info)
645648
else pre
646649

tests/pos/i15666.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait GetInt {
2+
def value: Int // if we add inline here, the program compiles
3+
}
4+
5+
class Newtype {
6+
def f: Int = ???
7+
8+
val g = new GetInt {
9+
inline def value: Int = f // has to be inline to crash
10+
}
11+
}

0 commit comments

Comments
 (0)