Handle inherited fields correctly.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
class Foo {
|
||||
foo(a, b) {
|
||||
_field1 = a
|
||||
_field2 = b
|
||||
}
|
||||
|
||||
fooPrint {
|
||||
io.write(_field1)
|
||||
io.write(_field2)
|
||||
}
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
bar(a, b) {
|
||||
_field1 = a
|
||||
_field2 = b
|
||||
}
|
||||
|
||||
barPrint {
|
||||
io.write(_field1)
|
||||
io.write(_field2)
|
||||
}
|
||||
}
|
||||
|
||||
var bar = Bar.new
|
||||
bar.foo("foo 1", "foo 2")
|
||||
bar.bar("bar 1", "bar 2")
|
||||
|
||||
bar.fooPrint
|
||||
// expect: foo 1
|
||||
// expect: foo 2
|
||||
|
||||
bar.barPrint
|
||||
// expect: bar 1
|
||||
// expect: bar 2
|
||||
@@ -0,0 +1,27 @@
|
||||
class Foo {
|
||||
methodOnFoo { io.write("foo") }
|
||||
method(a) { io.write("foo") }
|
||||
method(a, b, c) { io.write("foo") }
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
methodOnBar { io.write("bar") }
|
||||
method(a, b) { io.write("bar") }
|
||||
method(a, b, c, d) { io.write("bar") }
|
||||
}
|
||||
|
||||
var bar = Bar.new
|
||||
bar.methodOnFoo // expect: foo
|
||||
bar.methodOnBar // expect: bar
|
||||
|
||||
// Methods with different arity do not shadow each other.
|
||||
bar.method(1) // expect: foo
|
||||
bar.method(1, 2) // expect: bar
|
||||
bar.method(1, 2, 3) // expect: foo
|
||||
bar.method(1, 2, 3, 4) // expect: bar
|
||||
|
||||
// TODO(bob): Overriding (or BETA-style refining?).
|
||||
// TODO(bob): Private fields.
|
||||
// TODO(bob): Super (or inner) calls.
|
||||
// TODO(bob): Grammar for what expressions can follow "is".
|
||||
// TODO(bob): Prevent extending built-in types.
|
||||
@@ -0,0 +1,16 @@
|
||||
class A {}
|
||||
class B is A {}
|
||||
class C is B {}
|
||||
var a = A.new
|
||||
var b = B.new
|
||||
var c = C.new
|
||||
|
||||
io.write(a is A) // expect: true
|
||||
io.write(a is B) // expect: false
|
||||
io.write(a is C) // expect: false
|
||||
io.write(b is A) // expect: true
|
||||
io.write(b is B) // expect: true
|
||||
io.write(b is C) // expect: false
|
||||
io.write(c is A) // expect: true
|
||||
io.write(c is B) // expect: true
|
||||
io.write(c is C) // expect: true
|
||||
Reference in New Issue
Block a user