texplain.nim 4.7 KB

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