tgenconstraints.nim 500 B

1234567891011121314151617181920212223242526272829303132
  1. discard """
  2. errormsg: "cannot instantiate T2"
  3. file: "tgenconstraints.nim"
  4. line: 25
  5. disabled: true
  6. """
  7. type
  8. T1[T: int|string] = object
  9. x: T
  10. T2[T: Ordinal] = object
  11. x: T
  12. var x1: T1[int]
  13. var x2: T1[string]
  14. var x3: T2[int]
  15. proc foo[T](x: T): T2[T] {.discardable.} =
  16. var o: T1[T]
  17. foo(10)
  18. # XXX: allow type intersections in situation like this
  19. proc bar(x: int|TNumber): T1[type(x)] {.discardable.} =
  20. when type(x) is TNumber:
  21. var o: T2[type(x)]
  22. bar "test"
  23. bar 100
  24. bar 1.1