tobjcov.nim 407 B

123456789101112131415161718192021
  1. discard """
  2. action: compile
  3. """
  4. # Covariance is not type safe:
  5. type
  6. TA = object of RootObj
  7. a: int
  8. TB = object of TA
  9. b: array[0..5000_000, int]
  10. proc ap(x: var TA) = x.a = -1
  11. proc bp(x: var TB) = x.b[high(x.b)] = -1
  12. # in Nim proc (x: TB) is compatible to proc (x: TA),
  13. # but this is not type safe:
  14. var f = cast[proc (x: var TA) {.nimcall.}](bp)
  15. var a: TA
  16. f(a) # bp expects a TB, but gets a TA