tissue22142_shouldpass.nim 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. type
  2. A[T] = object of RootObj
  3. B[T] = object
  4. C = object
  5. x:int
  6. # change (previously true)
  7. block:
  8. proc test[J;H: A[J];T: B[H]](param: T): bool = false
  9. proc test[T](param: B[T]): bool = true
  10. doAssert test(B[A[int]]()) == false
  11. block: # object is more specific then `T`
  12. proc p[H:object;T:ptr[H]](param:T):bool = false
  13. proc p[T](param:ptr[T]):bool= true
  14. var l: ptr[C]
  15. doAssert p(l) == false
  16. block:
  17. proc p[T:A[object]](param:T):bool = false
  18. proc p[T](param: A[T]):bool= true
  19. doAssert p(A[C]()) == false
  20. block:
  21. proc test[H;T: A[H]](param: T): bool = false
  22. proc test(param: A): bool = true
  23. doAssert test(A[C]()) == false
  24. # change (previously ambiguous)
  25. block:
  26. proc p[T](a: A[T]): bool = false
  27. proc p[T: object](a: T): bool = true
  28. doAssert p(A[int]()) == false
  29. block: # A is more specific than `object`
  30. proc test[T: A](param: T): bool = false
  31. proc test[T: object](param: T): bool = true
  32. doAssert test(A[int]()) == false
  33. block:
  34. proc test[T: A](param: T): bool = false
  35. proc test(param: object): bool = true
  36. doAssert test(A[int]()) == false
  37. block:
  38. proc test[H;T: A[H]](param: T): bool = false
  39. proc test(param: object): bool = true
  40. doAssert test(A[C]()) == false
  41. block:
  42. proc test[H;T: A[B[H]]](param: T): bool = false
  43. proc test[T: object](param: T): bool = true
  44. doAssert test(A[B[int]]()) == false
  45. block:
  46. #[
  47. This was referenced in the nim compiler source (`sumGeneric`) as a case
  48. that was supposed to not be ambiguous, yet it was
  49. ]#
  50. proc test[J;H:A[J]; T: A[H]](param: T): bool = false
  51. proc test[H;T: A[H]](param: T): bool = true
  52. doAssert test(A[A[C]]()) == false
  53. block:
  54. proc test[J;T:A[J]](param: A[T]): bool = false
  55. proc test[T](param: A[T]): bool = true
  56. doAssert test(A[A[C]]()) == false
  57. block:
  58. proc test[T](param: A[T]): bool = false
  59. proc test[T: object](param: A[T]): bool = true
  60. doAssert test(A[C]()) == true
  61. block: #anti-regression (object is more specific then `T`)
  62. proc test[J;T:A[J]](param: A[T]): bool = false
  63. proc test(param: A[A[object]]): bool = true
  64. doAssert test(A[A[C]]()) == true