This page is no longer maintained — Please continue to the home page at www.scala-lang.org

generated outer refs in subclasses

No replies
Jan Vanek
Joined: 2011-08-23,
User offline. Last seen 42 years 45 weeks ago.
Hallo,
when I have:
    class A1 {        class Log {            var x = 0        }                def createLog = new Log    }         class B1 extends A1 {        class Log extends super.Log {            var y = 0        }                override def createLog = new Log    }
    val b1 = new B1    val l1 = b1.createLog    scala generates two outer references in the B1#Log class. When inspecting the instance l1 both outer references point to the same object.
It is possible to do:
    object A2 {        class Log(val o: A2) {            var x = 0        }    }         class A2 {        def createLog = new A2.Log(this)    }        object B2 {        class Log(override val o: B2) extends A2.Log(o) {            var y = 0         }    }        class B2 extends A2 {        override def createLog = new B2.Log(this)    }
    val b2 = new B2     val l2 = b2.createLog
Now the l2 contains only one "outer" reference o. The code is however more verbose.
Will it be optimized sometime in the future?
Thanks and regards,Jan

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland