Skip to content

Commit c54e942

Browse files
committed
Fix sorting of accessed this-proxies
They are sorted according to the nesting depth of the classes they represent. This is no necessarily the same as the nesting level of the symbols of the proxy classes. i1990a.scala shows an example where the two differ.
1 parent db295e8 commit c54e942

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,12 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
402402
def outerLevel(selfSym: Symbol): Int = classOf(selfSym).ownersIterator.length
403403

404404
// All needed this-proxies, sorted by nesting depth of the classes they represent (innermost first)
405-
val accessedSelfSyms = thisProxy.values.toList.map(_.symbol).sortBy(-outerLevel(_))
405+
val accessedSelfSyms =
406+
thisProxy.toList.sortBy {
407+
case (cls, proxy) => -outerLevel(cls)
408+
} map {
409+
case (cls, proxy) => proxy.symbol
410+
}
406411

407412
// Compute val-definitions for all this-proxies and append them to `bindingsBuf`
408413
var lastSelf: Symbol = NoSymbol

tests/pos/i1990a.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class A { self =>
2+
class Foo {
3+
inline def inlineMeth: Unit = {
4+
println(self)
5+
}
6+
}
7+
}
8+
9+
class C extends A {
10+
class B extends A
11+
}
12+
13+
object Test {
14+
def main(args: Array[String]): Unit = {
15+
val c = new C
16+
val b = new c.B
17+
18+
(new b.Foo).inlineMeth
19+
}
20+
}

0 commit comments

Comments
 (0)