Inheritance 13
This commit is contained in:
parent
d8ac625429
commit
848c846e09
12 changed files with 117 additions and 7 deletions
|
|
@ -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{
|
||||
|
|
|
|||
3
test/err/super_outside_class.lox
Normal file
3
test/err/super_outside_class.lox
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
super.notEvenInAClass();
|
||||
|
||||
8
test/err/super_without_superclass.lox
Normal file
8
test/err/super_without_superclass.lox
Normal 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
36
test/super.lox
Normal 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();
|
||||
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue