tobjecttyperel2.nim 665 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. discard """
  2. output: '''1
  3. a
  4. 13'''
  5. """
  6. # bug #5621 #5615
  7. type
  8. Obj5[T] = ref object of RootObj
  9. x_impl: T
  10. proc x[T](v476205: Obj5[T]): T {.used.} =
  11. v476205.x_impl
  12. type
  13. Obj6[T, U] = ref object of Obj5[T]
  14. y_impl: U
  15. proc newObj6[T, U](x: T; y: U): Obj6[T, U] =
  16. new(result)
  17. result.x_impl = x
  18. result.y_impl = y
  19. proc x[T, U](v477606: Obj6[T, U]): T {.used.} =
  20. v477606.x_impl
  21. proc y[T, U](v477608: Obj6[T, U]): U {.used.} =
  22. v477608.y_impl
  23. let e = newObj6(1, "a")
  24. echo e.x
  25. echo e.y
  26. type
  27. Fruit[T] = ref object of RootObj
  28. Apple[T] = ref object of Fruit[T]
  29. proc getColor[T](v: Fruit[T]): T = 13
  30. var w: Apple[int]
  31. let r = getColor(w)
  32. echo r