tobjcov.nim 375 B

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