Print missing case labels (#10600)
This commit is contained in:
parent
bcbe130ea7
commit
594c2576e6
4 changed files with 142 additions and 2 deletions
|
|
@ -873,6 +873,9 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode =
|
|||
if chckCovered:
|
||||
if covered == toCover(c, n.sons[0].typ):
|
||||
hasElse = true
|
||||
elif n.sons[0].typ.kind == tyEnum:
|
||||
localError(c.config, n.info, "not all cases are covered; missing: {$1}" %
|
||||
formatMissingEnums(n))
|
||||
else:
|
||||
localError(c.config, n.info, "not all cases are covered")
|
||||
closeScope(c)
|
||||
|
|
|
|||
|
|
@ -608,6 +608,24 @@ proc toCover(c: PContext, t: PType): BiggestInt =
|
|||
|
||||
proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
||||
father: PNode, rectype: PType, hasCaseFields = false)
|
||||
|
||||
proc formatMissingEnums(n: PNode): string =
|
||||
var coveredCases = initIntSet()
|
||||
for i in 1 ..< n.len:
|
||||
let ofBranch = n[i]
|
||||
for j in 0 ..< ofBranch.len - 1:
|
||||
let child = ofBranch[j]
|
||||
if child.kind == nkIntLit:
|
||||
coveredCases.incl(child.intVal.int)
|
||||
elif child.kind == nkRange:
|
||||
for k in child[0].intVal.int .. child[1].intVal.int:
|
||||
coveredCases.incl k
|
||||
for child in n[0].typ.n.sons:
|
||||
if child.sym.position notin coveredCases:
|
||||
if result.len > 0:
|
||||
result.add ", "
|
||||
result.add child.sym.name.s
|
||||
|
||||
proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
||||
father: PNode, rectype: PType) =
|
||||
var a = copyNode(n)
|
||||
|
|
@ -644,7 +662,11 @@ proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
|||
delSon(b, sonsLen(b) - 1)
|
||||
semRecordNodeAux(c, lastSon(n.sons[i]), check, pos, b, rectype, hasCaseFields = true)
|
||||
if chckCovered and covered != toCover(c, a.sons[0].typ):
|
||||
localError(c.config, a.info, "not all cases are covered")
|
||||
if a.sons[0].typ.kind == tyEnum:
|
||||
localError(c.config, a.info, "not all cases are covered; missing: {$1}" %
|
||||
formatMissingEnums(a))
|
||||
else:
|
||||
localError(c.config, a.info, "not all cases are covered")
|
||||
addSon(father, a)
|
||||
|
||||
proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue