tmissingbracket.nim 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. discard """
  2. output: '''
  3. Subobject test called
  4. 5
  5. '''
  6. """
  7. type
  8. TClassOfTCustomObject {.pure, inheritable.} = object
  9. base* : ptr TClassOfTCustomObject
  10. className* : string
  11. TClassOfTobj = object of TClassOfTCustomObject
  12. nil
  13. TCustomObject {.inheritable.} = ref object
  14. class* : ptr TClassOfTCustomObject
  15. TObj = ref object of TCustomObject
  16. data: int
  17. var ClassOfTObj: TClassOfTObj
  18. proc initClassOfTObj() =
  19. ClassOfTObj.base = nil
  20. ClassOfTObj.className = "TObj"
  21. initClassOfTObj()
  22. proc initialize*(self: TObj) =
  23. self.class = addr ClassOfTObj
  24. # this generates wrong C code: && instead of &
  25. proc newInstance(T: typedesc): T =
  26. mixin initialize
  27. new(result)
  28. initialize(result)
  29. var o = TObj.newInstance()
  30. type
  31. TestObj* = object of RootObj
  32. t:int
  33. SubObject* = object of TestObj
  34. method test*(t:var TestObj) {.base.} =
  35. echo "test called"
  36. method test*(t:var SubObject) =
  37. echo "Subobject test called"
  38. t.t= 5
  39. var a: SubObject
  40. a.test()
  41. echo a.t