toutparam_subtype.nim 438 B

12345678910111213141516171819202122232425
  1. discard """
  2. cmd: "nim check $file"
  3. action: "compile"
  4. errormsg: "type mismatch: got <Subclass[system.int]>"
  5. line: 21
  6. """
  7. {.experimental: "strictDefs".}
  8. type
  9. Superclass[T] = object of RootObj
  10. a: T
  11. Subclass[T] = object of Superclass[T]
  12. s: string
  13. proc init[T](x: out Superclass[T]) =
  14. x = Superclass(a: 8)
  15. proc subtypeCheck =
  16. var v: Subclass[int]
  17. init(v)
  18. echo v.s # the 's' field was never initialized!
  19. subtypeCheck()