tdistinct_issues.nim 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. discard """
  2. output: '''
  3. A
  4. A
  5. 25.0
  6. 210.0
  7. apr
  8. '''
  9. """
  10. block t4435:
  11. type
  12. A[T] = distinct T
  13. B[T] = distinct T
  14. proc foo[T](x:A[T]) = echo "A"
  15. proc foo[T](x:B[T]) = echo "B"
  16. proc bar(x:A) = echo "A"
  17. proc bar(x:B) = echo "B"
  18. var
  19. a:A[int]
  20. foo(a) # fine
  21. bar(a) # testdistinct.nim(14, 4) Error: ambiguous call; both testdistinct.bar(x: A) and testdistinct.bar(x: B) match for: (A[system.int])
  22. block t7010:
  23. type MyInt = distinct int
  24. proc `+`(x: MyInt, y: MyInt): MyInt {.borrow.}
  25. proc `+=`(x: var MyInt, y: MyInt) {.borrow.}
  26. proc `=`(x: var MyInt, y: MyInt) {.borrow.}
  27. var next: MyInt
  28. proc getNext() : MyInt =
  29. result = next
  30. next += 1.MyInt
  31. next = next + 1.MyInt
  32. block t9079:
  33. type
  34. Dollars = distinct float
  35. proc `$`(d: Dollars): string {.borrow.}
  36. proc `*`(a, b: Dollars): Dollars {.borrow.}
  37. proc `+`(a, b: Dollars): Dollars {.borrow.}
  38. var a = Dollars(20)
  39. a = Dollars(25.0)
  40. echo a
  41. a = 10.Dollars * (20.Dollars + 1.Dollars)
  42. echo a
  43. block t9322:
  44. type Fix = distinct string
  45. proc `$`(f: Fix): string {.borrow.}
  46. proc mystr(s: string) =
  47. echo s
  48. mystr($Fix("apr"))