texplain.nim 6.0 KB

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