super.gd 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. class Say:
  2. var prefix = "S"
  3. func greet():
  4. prefix = "S Greeted"
  5. print("hello")
  6. func say(name):
  7. print(prefix, " say something ", name)
  8. class SayAnotherThing extends Say:
  9. # This currently crashes the engine.
  10. #var prefix = "SAT"
  11. func greet():
  12. prefix = "SAT Greeted"
  13. print("hi")
  14. func say(name):
  15. print(prefix, " say another thing ", name)
  16. class SayNothing extends Say:
  17. # This currently crashes the engine.
  18. #var prefix = "SN"
  19. func greet():
  20. super()
  21. prefix = "SN Greeted"
  22. print("howdy, see above")
  23. func greet_prefix_before_super():
  24. prefix = "SN Greeted"
  25. super.greet()
  26. print("howdy, see above")
  27. func say(name):
  28. super(name + " super'd")
  29. print(prefix, " say nothing... or not? ", name)
  30. func test():
  31. var say = Say.new()
  32. say.greet()
  33. say.say("foo")
  34. print()
  35. var say_another_thing = SayAnotherThing.new()
  36. say_another_thing.greet()
  37. say_another_thing.say("bar")
  38. print()
  39. var say_nothing = SayNothing.new()
  40. say_nothing.greet()
  41. print(say_nothing.prefix)
  42. say_nothing.greet_prefix_before_super()
  43. print(say_nothing.prefix)
  44. # This currently triggers a compiler bug: "compiler bug, function name not found"
  45. #say_nothing.say("baz")