t5540.nim 827 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # bug #5540; works in 1.2.0
  2. # fails in 1.0 (Error: cannot generate VM code for)
  3. # fails in 0.18.0 (Error: type mismatch: got <type T>)
  4. block:
  5. type
  6. Fruit = object
  7. Yellow = object
  8. a: int
  9. template getColor(x: typedesc[Fruit]): typedesc = Yellow
  10. type
  11. Banana[T] = object
  12. b: T
  13. a: getColor(Fruit)
  14. Apple[T] = object
  15. a: T
  16. b: getColor(T)
  17. block:
  18. var x: Banana[int]
  19. doAssert x.b == 0
  20. doAssert x.a is Yellow
  21. block:
  22. var x: Apple[Fruit]
  23. doAssert x.b is Yellow
  24. block:
  25. type
  26. Fruit = object
  27. Yellow = object
  28. a: int
  29. template getColor(x: typedesc[Fruit]): typedesc = Yellow
  30. type
  31. Banana[T] = object
  32. b: T
  33. a: getColor(Fruit)
  34. Apple[T] = object
  35. a: T
  36. b: getColor(T)
  37. var x: Banana[int]
  38. x.b = 13
  39. x.a.a = 17