Skip to content

Commit 595e06d

Browse files
authored
filters duplicated error messages using line infos (#1097)
This can remove duplicated error messages result from generic instantiations. Fixes a part of #1066.
1 parent c446329 commit 595e06d

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/nimony/reporters.nim

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# See the file "license.txt", included in this
55
# distribution, for details about the copyright.
66

7-
import std / [syncio, strutils, os, terminal, assertions]
7+
import std / [syncio, strutils, os, terminal, assertions, sets]
88
import nifstreams, nifcursors, bitabs, lineinfos
99

1010
type
@@ -21,6 +21,8 @@ type
2121
assertOnError*: bool
2222
warnings*: int
2323
errors*: int
24+
reportedErrSources: HashSet[PackedLineInfo]
25+
2426

2527
proc useColors*(): bool = terminal.isatty(stdout)
2628

@@ -108,6 +110,7 @@ proc reportErrors*(dest: var TokenBuf): int =
108110
if dest[i].kind == ParLe and dest[i].tagId == errTag:
109111
inc result
110112
let info = dest[i].info
113+
let doReport = not r.reportedErrSources.containsOrIncl(info)
111114
inc i
112115
# original expression, optional:
113116
if dest[i].kind == DotToken:
@@ -118,11 +121,13 @@ proc reportErrors*(dest: var TokenBuf): int =
118121
endRead(dest)
119122
# instantiation contexts:
120123
while dest[i].kind == DotToken:
121-
r.trace infoToStr(dest[i].info), "instantiation from here"
124+
if doReport:
125+
r.trace infoToStr(dest[i].info), "instantiation from here"
122126
inc i
123127
# error message:
124128
assert dest[i].kind == StringLit
125-
r.error infoToStr(info), pool.strings[dest[i].litId]
129+
if doReport:
130+
r.error infoToStr(info), pool.strings[dest[i].litId]
126131
inc i
127132
else:
128133
inc i
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
tests/nimony/errmsgs/tbadconverter.nim(1, 1) Error: cannot attach converter to type (err Foo "undeclared identifier")
2-
tests/nimony/errmsgs/tbadconverter.nim(1, 11) Error: undeclared identifier
32
tests/nimony/errmsgs/tbadconverter.nim(1, 11) Error: undeclared identifier

tests/nimony/templates/tinvalidrecursion.msgs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ tests/nimony/templates/tinvalidrecursion.nim(2, 6) Trace: instantiation from her
22
tests/nimony/templates/tinvalidrecursion.nim(2, 6) Error: cannot expand template from prototype; possibly a recursive template call
33
tests/nimony/templates/tinvalidrecursion.nim(5, 7) Trace: instantiation from here
44
tests/nimony/templates/tinvalidrecursion.nim(8, 7) Trace: instantiation from here
5-
tests/nimony/templates/tinvalidrecursion.nim(8, 7) Error: cannot expand template from prototype; possibly a recursive template call
6-
tests/nimony/templates/tinvalidrecursion.nim(5, 7) Trace: instantiation from here
7-
tests/nimony/templates/tinvalidrecursion.nim(8, 7) Trace: instantiation from here
85
tests/nimony/templates/tinvalidrecursion.nim(8, 7) Error: cannot expand template from prototype; possibly a recursive template call

0 commit comments

Comments
 (0)