texplain.nim 4.1 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. """
  62. # line 80 HERE
  63. type
  64. ExplainedConcept {.explain.} = concept o
  65. o.foo is int
  66. o.bar is string
  67. RegularConcept = concept o
  68. o.foo is int
  69. o.bar is string
  70. NestedConcept = concept o
  71. o.foo is RegularConcept
  72. NonMatchingType = object
  73. foo: int
  74. bar: int
  75. MatchingType = object
  76. foo: int
  77. bar: string
  78. proc e(o: ExplainedConcept): int = 1
  79. proc e(i: int): int = i
  80. proc r[T](a: SomeNumber, b: T, c: auto) = discard
  81. proc r(o: RegularConcept): int = 1
  82. proc r(i: string): int = 1
  83. proc f(o: NestedConcept) = discard
  84. var n = NonMatchingType(foo: 10, bar: 20)
  85. var y = MatchingType(foo: 10, bar: "bar")
  86. # no diagnostic here:
  87. discard e(y)
  88. # explain that e(int) doesn't match
  89. discard e(y) {.explain.}
  90. # explain that e(ExplainedConcept) doesn't match
  91. echo(e(10) {.explain.}, 20)
  92. # explain that e(ExplainedConcept) doesn't again
  93. discard e(10)
  94. static:
  95. # provide diagnostics why the compile block failed
  96. assert(compiles(e(n)) {.explain.} == false)
  97. assert(compiles(r(n)) {.explain.} == false)
  98. assert(compiles(r(y)) {.explain.} == true)
  99. # these should not produce any output
  100. assert(compiles(r(10)) == false)
  101. assert(compiles(e(10)) == true)
  102. # finally, provide multiple nested explanations for failed matching
  103. # of regular concepts, even when the explain pragma is not used
  104. f(y)