tor_isnt_better.nim 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. type
  2. D[T] = object
  3. E[T] = object
  4. block: # PR #22261
  5. proc d(x: D):bool= false
  6. proc d(x: int | D[SomeInteger]):bool= true
  7. doAssert d(D[5]()) == false
  8. block: # bug #8568
  9. #[
  10. Since PR #22261 and amendment has been made. Since D is a subset of D | E but
  11. not the other way around `checkGeneric` should favor proc g(a: D) instead
  12. of asserting ambiguity
  13. ]#
  14. proc g(a: D|E): string = "foo D|E"
  15. proc g(a: D): string = "foo D"
  16. doAssert g(D[int]()) == "foo D"
  17. type Obj1[T] = object
  18. v: T
  19. converter toObj1[T](t: T): Obj1[T] = return Obj1[T](v: t)
  20. block: # issue #10019
  21. proc fun1[T](elements: seq[T]): string = "fun1 seq"
  22. proc fun1(o: object|tuple): string = "fun1 object|tuple"
  23. proc fun2[T](elements: openArray[T]): string = "fun2 openarray"
  24. proc fun2(o: object): string = "fun2 object"
  25. proc fun_bug[T](elements: openArray[T]): string = "fun_bug openarray"
  26. proc fun_bug(o: object|tuple):string = "fun_bug object|tuple"
  27. proc main() =
  28. var x = @["hello", "world"]
  29. block:
  30. # no ambiguity error shown here even though this would compile if we remove either 1st or 2nd overload of fun1
  31. doAssert fun1(x) == "fun1 seq"
  32. block:
  33. # ditto
  34. doAssert fun2(x) == "fun2 openarray"
  35. block:
  36. # Error: ambiguous call; both t0065.fun_bug(elements: openarray[T])[declared in t0065.nim(17, 5)] and t0065.fun_bug(o: object or tuple)[declared in t0065.nim(20, 5)] match for: (array[0..1, string])
  37. doAssert fun_bug(x) == "fun_bug openarray"
  38. main()