Files
wren/test/language/inheritance/inherit_from_enclosing.wren
Bob Nystrom c472a61bff Inherit methods from enclosing classes.
Like NewtonScript, the inner classes superclasses take precedence, but
if not found there then the enclosing classes are searched.

This code is still a bit hacky in some corners, but it's a step in the
right direction.
2015-12-21 17:05:46 -08:00

35 lines
918 B
Plaintext

class Outer {
construct new() {}
def outerBefore() { System.print("Outer before") }
def shadowOuter() { System.print("bad") }
class Inner {
construct new() {}
def innerBefore() { System.print("Inner before") }
def shadowInner() { System.print("bad") }
class MoreInner {
construct new() {}
def shadowOuter() { System.print("ok") }
def shadowInner() { System.print("ok") }
}
def innerAfter() { System.print("Inner after") }
}
def outerAfter() { System.print("Outer after") }
}
var moreInner = Outer.new().Inner.new().MoreInner.new()
moreInner.outerBefore() // expect: Outer before
moreInner.outerAfter() // expect: Outer after
moreInner.innerBefore() // expect: Inner before
moreInner.innerAfter() // expect: Inner after
moreInner.shadowOuter() // expect: ok
moreInner.shadowInner() // expect: ok
// TODO: Test how super interacts with enclosing classes.