tobject3.nim 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. discard """
  2. output: '''TBar2
  3. TFoo
  4. '''
  5. """
  6. ## XXX this output needs to be adapted for VCC which produces different results.
  7. # It turned out that it's hard to generate correct for these two test cases at
  8. # the same time.
  9. type
  10. TFoo = ref object of RootObj
  11. Data: int
  12. TBar = ref object of TFoo
  13. nil
  14. TBar2 = ref object of TBar
  15. d2: int
  16. template super(self: TBar): TFoo = self
  17. template super(self: TBar2): TBar = self
  18. proc Foo(self: TFoo) =
  19. echo "TFoo"
  20. #proc Foo(self: TBar) =
  21. # echo "TBar"
  22. # Foo(super(self))
  23. # works when this code is uncommented
  24. proc Foo(self: TBar2) =
  25. echo "TBar2"
  26. Foo(super(self))
  27. var b: TBar2
  28. new(b)
  29. Foo(b)
  30. # bug #837
  31. type
  32. PView* = ref TView
  33. TView* {.inheritable.} = object
  34. data: int
  35. PWindow* = ref TWindow
  36. TWindow* = object of TView
  37. data3: int
  38. PDesktop* = ref TDesktop
  39. TDesktop* = object of TView
  40. data2: int
  41. proc makeDesktop(): PDesktop = new(TDesktop)
  42. proc makeWindow(): PWindow = new(TWindow)
  43. proc thisCausesError(a: PView, b: PView) =
  44. discard
  45. var dd = makeDesktop()
  46. var aa = makeWindow()
  47. thisCausesError(dd, aa)
  48. # bug #5892
  49. type
  50. Foo6 = distinct array[4, float32]
  51. AnotherFoo = distinct array[4, float32]
  52. AbstractAnimationSampler* = ref object of RootObj
  53. AnimationSampler*[T] = ref object of AbstractAnimationSampler
  54. sampleImpl: proc(s: AnimationSampler[T], p: float): T
  55. ArrayAnimationSampler*[T] = ref object of AnimationSampler[T]
  56. proc newArrayAnimationSampler*[T](): ArrayAnimationSampler[T] =
  57. result.new()
  58. result.sampleImpl = nil
  59. discard newArrayAnimationSampler[Foo6]()
  60. discard newArrayAnimationSampler[AnotherFoo]()
  61. type
  62. DefaultIsNone* = pointer | ptr | ref | proc {.nimcall.} | cstring | cstringArray
  63. OptionKind* {.pure.} = enum None, Some
  64. OptionA* [T] = object of RootObj
  65. when T is DefaultIsNone:
  66. value: T
  67. else:
  68. value: T
  69. kind: OptionKind
  70. SomeA* [T] = object of OptionA[T]