tdistinct_issues.nim 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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"))
  49. block: # bug #13517
  50. type MyUint64 = distinct uint64
  51. proc `==`(a: MyUint64, b: uint64): bool = uint64(a) == b
  52. block:
  53. doAssert MyUint64.high is MyUint64
  54. doAssert MyUint64.high == 18446744073709551615'u64
  55. static:
  56. doAssert MyUint64.high is MyUint64
  57. doAssert MyUint64.high == 18446744073709551615'u64