t976.nim 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. discard """
  2. output: '''
  3. Printable
  4. '''
  5. joinable: false
  6. """
  7. #[
  8. The converter is a proper example of a confounding variable
  9. Moved to an isolated file
  10. ]#
  11. type
  12. Obj1[T] = object
  13. v: T
  14. converter toObj1[T](t: T): Obj1[T] =
  15. return Obj1[T](v: t)
  16. block t976:
  17. type
  18. int1 = distinct int
  19. int2 = distinct int
  20. int1g = concept x
  21. x is int1
  22. int2g = concept x
  23. x is int2
  24. proc take[T: int1g](value: int1) =
  25. when T is int2:
  26. static: error("killed in take(int1)")
  27. proc take[T: int2g](vale: int2) =
  28. when T is int1:
  29. static: error("killed in take(int2)")
  30. var i1: int1 = 1.int1
  31. var i2: int2 = 2.int2
  32. take[int1](i1)
  33. take[int2](i2)
  34. template reject(e) =
  35. static: assert(not compiles(e))
  36. reject take[string](i2)
  37. reject take[int1](i2)
  38. # bug #6249
  39. type
  40. Obj2 = ref object
  41. PrintAble = concept x
  42. $x is string
  43. proc `$`[T](nt: Obj1[T]): string =
  44. when T is PrintAble: result = "Printable"
  45. else: result = "Non Printable"
  46. echo Obj2()