texplain.nim 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. discard """
  2. cmd: "nim c --verbosity:0 --colors:off $file"
  3. nimout: '''
  4. Hint: texplain [Processing]
  5. texplain.nim(118, 10) Hint: Non-matching candidates for e(y)
  6. proc e(i: int): int
  7. texplain.nim(121, 7) Hint: Non-matching candidates for e(10)
  8. proc e(o: ExplainedConcept): int
  9. texplain.nim(84, 6) ExplainedConcept: undeclared field: 'foo'
  10. texplain.nim(84, 6) ExplainedConcept: undeclared field: '.'
  11. texplain.nim(84, 6) ExplainedConcept: expression '.' cannot be called
  12. texplain.nim(84, 5) ExplainedConcept: concept predicate failed
  13. texplain.nim(85, 6) ExplainedConcept: undeclared field: 'bar'
  14. texplain.nim(85, 6) ExplainedConcept: undeclared field: '.'
  15. texplain.nim(85, 6) ExplainedConcept: expression '.' cannot be called
  16. texplain.nim(84, 5) ExplainedConcept: concept predicate failed
  17. texplain.nim(124, 10) Hint: Non-matching candidates for e(10)
  18. proc e(o: ExplainedConcept): int
  19. texplain.nim(84, 6) ExplainedConcept: undeclared field: 'foo'
  20. texplain.nim(84, 6) ExplainedConcept: undeclared field: '.'
  21. texplain.nim(84, 6) ExplainedConcept: expression '.' cannot be called
  22. texplain.nim(84, 5) ExplainedConcept: concept predicate failed
  23. texplain.nim(85, 6) ExplainedConcept: undeclared field: 'bar'
  24. texplain.nim(85, 6) ExplainedConcept: undeclared field: '.'
  25. texplain.nim(85, 6) ExplainedConcept: expression '.' cannot be called
  26. texplain.nim(84, 5) ExplainedConcept: concept predicate failed
  27. texplain.nim(128, 20) Error: type mismatch: got <NonMatchingType>
  28. but expected one of:
  29. proc e(o: ExplainedConcept): int
  30. texplain.nim(128, 9) template/generic instantiation of `assert` from here
  31. texplain.nim(84, 5) ExplainedConcept: concept predicate failed
  32. proc e(i: int): int
  33. expression: e(n)
  34. texplain.nim(129, 20) Error: type mismatch: got <NonMatchingType>
  35. but expected one of:
  36. proc r(o: RegularConcept): int
  37. texplain.nim(129, 9) template/generic instantiation of `assert` from here
  38. texplain.nim(88, 5) RegularConcept: concept predicate failed
  39. proc r[T](a: SomeNumber; b: T; c: auto)
  40. proc r(i: string): int
  41. expression: r(n)
  42. texplain.nim(130, 20) Hint: Non-matching candidates for r(y)
  43. proc r[T](a: SomeNumber; b: T; c: auto)
  44. proc r(i: string): int
  45. texplain.nim(138, 2) Error: type mismatch: got <MatchingType>
  46. but expected one of:
  47. proc f(o: NestedConcept)
  48. texplain.nim(88, 6) RegularConcept: undeclared field: 'foo'
  49. texplain.nim(88, 6) RegularConcept: undeclared field: '.'
  50. texplain.nim(88, 6) RegularConcept: expression '.' cannot be called
  51. texplain.nim(88, 5) RegularConcept: concept predicate failed
  52. texplain.nim(89, 6) RegularConcept: undeclared field: 'bar'
  53. texplain.nim(89, 6) RegularConcept: undeclared field: '.'
  54. texplain.nim(89, 6) RegularConcept: expression '.' cannot be called
  55. texplain.nim(88, 5) RegularConcept: concept predicate failed
  56. texplain.nim(92, 5) NestedConcept: concept predicate failed
  57. expression: f(y)
  58. '''
  59. errormsg: "type mismatch: got <MatchingType>"
  60. line: 138
  61. disabled: 32bit
  62. """
  63. # disabled on 32 bit, because the order of suggested alternatives ``r`` differs
  64. # proc r[T](a: SomeNumber; b: T; c: auto)
  65. # proc r(i: string): int
  66. # proc r(o: RegularConcept): int
  67. # line 80 HERE
  68. type
  69. ExplainedConcept {.explain.} = concept o
  70. o.foo is int
  71. o.bar is string
  72. RegularConcept = concept o
  73. o.foo is int
  74. o.bar is string
  75. NestedConcept = concept o
  76. o.foo is RegularConcept
  77. NonMatchingType = object
  78. foo: int
  79. bar: int
  80. MatchingType = object
  81. foo: int
  82. bar: string
  83. proc e(o: ExplainedConcept): int = 1
  84. proc e(i: int): int = i
  85. proc r[T](a: SomeNumber, b: T, c: auto) = discard
  86. proc r(o: RegularConcept): int = 1
  87. proc r(i: string): int = 1
  88. proc f(o: NestedConcept) = discard
  89. var n = NonMatchingType(foo: 10, bar: 20)
  90. var y = MatchingType(foo: 10, bar: "bar")
  91. # no diagnostic here:
  92. discard e(y)
  93. # explain that e(int) doesn't match
  94. discard e(y) {.explain.}
  95. # explain that e(ExplainedConcept) doesn't match
  96. echo(e(10) {.explain.}, 20)
  97. # explain that e(ExplainedConcept) doesn't again
  98. discard e(10)
  99. static:
  100. # provide diagnostics why the compile block failed
  101. assert(compiles(e(n)) {.explain.} == false)
  102. assert(compiles(r(n)) {.explain.} == false)
  103. assert(compiles(r(y)) {.explain.} == true)
  104. # these should not produce any output
  105. assert(compiles(r(10)) == false)
  106. assert(compiles(e(10)) == true)
  107. # finally, provide multiple nested explanations for failed matching
  108. # of regular concepts, even when the explain pragma is not used
  109. f(y)