aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-02-19 09:29:28 +0100
committerMartin Odersky <odersky@gmail.com>2017-02-19 09:29:41 +0100
commitc54e942ef6275fc0c61c051539a1b37f4e12123c (patch)
tree744cbe78aa878ccb9ca9c9ba150cdbe8a5116fb8
parentdb295e8fb13c8490b96d84e8357a75550ebdebfd (diff)
downloaddotty-c54e942ef6275fc0c61c051539a1b37f4e12123c.tar.gz
dotty-c54e942ef6275fc0c61c051539a1b37f4e12123c.tar.bz2
dotty-c54e942ef6275fc0c61c051539a1b37f4e12123c.zip
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.
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Inliner.scala7
-rw-r--r--tests/pos/i1990a.scala20
2 files changed, 26 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala
index cfc0003c6..6cf69b97c 100644
--- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala
@@ -402,7 +402,12 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
def outerLevel(selfSym: Symbol): Int = classOf(selfSym).ownersIterator.length
// All needed this-proxies, sorted by nesting depth of the classes they represent (innermost first)
- val accessedSelfSyms = thisProxy.values.toList.map(_.symbol).sortBy(-outerLevel(_))
+ val accessedSelfSyms =
+ thisProxy.toList.sortBy {
+ case (cls, proxy) => -outerLevel(cls)
+ } map {
+ case (cls, proxy) => proxy.symbol
+ }
// Compute val-definitions for all this-proxies and append them to `bindingsBuf`
var lastSelf: Symbol = NoSymbol
diff --git a/tests/pos/i1990a.scala b/tests/pos/i1990a.scala
new file mode 100644
index 000000000..f6f95ee36
--- /dev/null
+++ b/tests/pos/i1990a.scala
@@ -0,0 +1,20 @@
+class A { self =>
+ class Foo {
+ inline def inlineMeth: Unit = {
+ println(self)
+ }
+ }
+}
+
+class C extends A {
+ class B extends A
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ val c = new C
+ val b = new c.B
+
+ (new b.Foo).inlineMeth
+ }
+}