super.gd 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. @warning_ignore("unsafe_call_argument")
  29. super(name + " super'd")
  30. print(prefix, " say nothing... or not? ", name)
  31. func test():
  32. var say = Say.new()
  33. say.greet()
  34. say.say("foo")
  35. print()
  36. var say_another_thing = SayAnotherThing.new()
  37. say_another_thing.greet()
  38. say_another_thing.say("bar")
  39. print()
  40. var say_nothing = SayNothing.new()
  41. say_nothing.greet()
  42. print(say_nothing.prefix)
  43. say_nothing.greet_prefix_before_super()
  44. print(say_nothing.prefix)
  45. # This currently triggers a compiler bug: "compiler bug, function name not found"
  46. #say_nothing.say("baz")