Inheritance 13

This commit is contained in:
nazrin 2025-06-02 23:44:23 +00:00
parent d8ac625429
commit 848c846e09
12 changed files with 117 additions and 7 deletions

View file

@ -16,12 +16,15 @@ void main(){
"./test/fib_recursive.lox".match(fib(34));
"./test/fib_closure.lox".match(fib(34));
"./test/class.lox".match("The German chocolate cake is delicious!\n");
"./test/super.lox".match("Fry until golden brown.\nPipe full of custard and coat with chocolate.\nA method\n");
"./test/err/invalid_syntax.lox".shouldFail(RetVal.other);
"./test/err/already_defined.lox".shouldFail(RetVal.other, "Already a variable with this name");
"./test/err/undefined_var.lox".shouldFail(RetVal.runtime, "Undefined variable");
"./test/err/self_ref_vardecl.lox".shouldFail(RetVal.runtime, "Undefined variable");
"./test/err/invalid_syntax.lox".shouldFail(RetVal.other);
"./test/err/global_scope_return.lox".shouldFail(RetVal.other, "Can't return from top-level code");
"./test/err/super_outside_class.lox".shouldFail(RetVal.other, "Can't use 'super' outside of a class");
"./test/err/super_without_superclass.lox".shouldFail(RetVal.other, "Can't use 'super' in a class with no superclass");
}
enum RetVal{

View file

@ -0,0 +1,3 @@
super.notEvenInAClass();

View file

@ -0,0 +1,8 @@
class Eclair{
cook(){
super.cook();
print "Pipe full of crème pâtissière.";
}
}

36
test/super.lox Normal file
View file

@ -0,0 +1,36 @@
class Doughnut{
cook(){
print "Fry until golden brown.";
}
}
class BostonCream < Doughnut{
cook(){
super.cook();
print "Pipe full of custard and coat with chocolate.";
}
}
BostonCream().cook();
class A{
method(){
print "A method";
}
}
class B < A{
method(){
print "B method";
}
test(){
super.method();
}
}
class C < B{}
C().test();

View file

@ -1,2 +0,0 @@