tmissingbracket.nim 993 B

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