fix #18332: XDeclaredButNotUsed hints now in deterministic order (#18336)

This commit is contained in:
Timothee Cour
2021-06-23 23:31:55 -07:00
committed by GitHub
parent 0f91b67f5c
commit f258e4e70c
2 changed files with 19 additions and 15 deletions

View File

@@ -8,11 +8,10 @@
#
# This module implements lookup helpers.
import std/[algorithm, strutils]
import
intsets, ast, astalgo, idents, semdata, types, msgs, options,
renderer, nimfix/prettybase, lineinfos, strutils,
modulegraphs, astmsgs
renderer, nimfix/prettybase, lineinfos, modulegraphs, astmsgs
proc ensureNoMissingOrUnusedSymbols(c: PContext; scope: PScope)
@@ -268,6 +267,7 @@ proc ensureNoMissingOrUnusedSymbols(c: PContext; scope: PScope) =
var it: TTabIter
var s = initTabIter(it, scope.symbols)
var missingImpls = 0
var unusedSyms: seq[tuple[sym: PSym, key: string]]
while s != nil:
if sfForward in s.flags and s.kind notin {skType, skModule}:
# too many 'implementation of X' errors are annoying
@@ -282,8 +282,10 @@ proc ensureNoMissingOrUnusedSymbols(c: PContext; scope: PScope) =
# maybe they can be made skGenericParam as well.
if s.typ != nil and tfImplicitTypeParam notin s.typ.flags and
s.typ.kind != tyGenericParam:
message(c.config, s.info, hintXDeclaredButNotUsed, s.name.s)
unusedSyms.add (s, toFileLineCol(c.config, s.info))
s = nextIter(it, scope.symbols)
for (s, _) in sortedByIt(unusedSyms, it.key):
message(c.config, s.info, hintXDeclaredButNotUsed, s.name.s)
proc wrongRedefinition*(c: PContext; info: TLineInfo, s: string;
conflictsWith: TLineInfo) =

View File

@@ -1,16 +1,18 @@
discard """
matrix: "--hint:all:off --hint:XDeclaredButNotUsed"
nimoutFull: true
nimout: '''
treportunused.nim(19, 10) Hint: 's1' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(26, 5) Hint: 's8' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(22, 6) Hint: 's4' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(25, 7) Hint: 's7' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(24, 7) Hint: 's6' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(23, 6) Hint: 's5' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(20, 10) Hint: 's2' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(29, 6) Hint: 's11' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(27, 5) Hint: 's9' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(21, 10) Hint: 's3' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(28, 6) Hint: 's10' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(21, 10) Hint: 's1' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(22, 10) Hint: 's2' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(23, 10) Hint: 's3' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(24, 6) Hint: 's4' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(25, 6) Hint: 's5' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(26, 7) Hint: 's6' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(27, 7) Hint: 's7' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(28, 5) Hint: 's8' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(29, 5) Hint: 's9' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(30, 6) Hint: 's10' is declared but not used [XDeclaredButNotUsed]
treportunused.nim(31, 6) Hint: 's11' is declared but not used [XDeclaredButNotUsed]
'''
action: compile
"""