tusertypeclasses2.nim 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. discard """
  2. targets: "c js"
  3. """
  4. block:
  5. type
  6. hasFieldX = concept z
  7. z.x is int
  8. obj_x = object
  9. x: int
  10. ref_obj_x = ref object
  11. x: int
  12. ref_to_obj_x = ref obj_x
  13. p_o_x = ptr obj_x
  14. v_o_x = var obj_x
  15. template check(x) =
  16. static: assert(x)
  17. check obj_x is hasFieldX
  18. check ref_obj_x is hasFieldX
  19. check ref_to_obj_x is hasFieldX
  20. check p_o_x is hasFieldX
  21. check v_o_x is hasFieldX
  22. block:
  23. type
  24. Foo = concept x
  25. x.isFoo
  26. Bar = distinct float
  27. template isFoo(x: Bar): untyped = true
  28. proc foo(x: var Foo) =
  29. float(x) = 1.0
  30. proc foo2(x: var Bar) =
  31. float(x) = 1.0
  32. proc foo3(x: var (Bar|SomeNumber)) =
  33. float(x) = 1.0
  34. proc foo4(x: var any) =
  35. float(x) = 1.0
  36. var x: Bar
  37. foo(x)
  38. foo2(x)
  39. foo3(x)
  40. foo4(x)
  41. block: # bug #9550
  42. block:
  43. type Foo = concept c
  44. for v in c: (v is char)
  45. func foo(c: Foo) = (for v in c: discard)
  46. foo @['a', 'b' ,'c']
  47. block:
  48. type Foo = concept c
  49. for v in c: (v is char)
  50. func foo(c: Foo) = (for v in c: discard)
  51. foo ['a', 'b' ,'c']