Runtime: add method dispatch for array/string/dict/number (.len, .push, .pop, .keys, .values, .has, .toInt) Stdlib: delete global len/push/pop/keys/values/has Tests/docs/examples: migrate to method style; add tests/test_builtin_methods_style.bob All tests pass Breaking: global len/push/pop/keys/values/has removed; use methods instead Parser/AST: add class/extends/extension/super, field initializers Runtime: shared methods with this injection; classParents/classTemplates; super resolution; ownerClass/currentClass; extension lookup order Builtins: method dispatch for array/string/dict/number (.len/.push/.pop/.keys/.values/.has/.toInt); remove global forms Tests/docs/examples: add/refresh for classes, inheritance, super, polymorphism; migrate to method style; all tests pass VS Code extension: update grammar/readme/snippets for new features
41 lines
1.1 KiB
Plaintext
41 lines
1.1 KiB
Plaintext
print("\n--- Test: Class Inheritance (extensions) ---");
|
|
|
|
class Animal { var name; func init(n) { this.name = n; } }
|
|
extension Animal { func speak() { return this.name + "?"; } }
|
|
|
|
class Dog extends Animal { }
|
|
extension Dog { func bark() { return this.name + " woof"; } }
|
|
|
|
var a = Animal("crit");
|
|
var d = Dog("fido");
|
|
|
|
assert(a.speak() == "crit?", "Animal.speak works");
|
|
assert(d.speak() == "fido?", "Dog inherits Animal.speak via extension chain");
|
|
assert(d.bark() == "fido woof", "Dog.bark works");
|
|
|
|
print("Inheritance via extensions: PASS");
|
|
|
|
|
|
print("\n--- Test: Class Inheritance (inline methods) ---");
|
|
|
|
class Animal2 {
|
|
var name;
|
|
func init(n) { this.name = n; }
|
|
func speak() { return this.name + "!"; }
|
|
}
|
|
|
|
class Dog2 extends Animal2 {
|
|
func bark() { return this.name + " woof"; }
|
|
}
|
|
|
|
var a2 = Animal2("crit");
|
|
var d2 = Dog2("fido");
|
|
|
|
assert(a2.speak() == "crit!", "Animal2.speak works (inline)");
|
|
assert(d2.speak() == "fido!", "Dog2 inherits Animal2.speak (inline)");
|
|
assert(d2.bark() == "fido woof", "Dog2.bark works (inline)");
|
|
|
|
print("Inheritance via inline methods: PASS");
|
|
|
|
|