better error messages for .raise effect analysis (#17595)
This commit is contained in:
parent
b18307f940
commit
ece7147734
1 changed files with 7 additions and 5 deletions
|
|
@ -304,8 +304,8 @@ proc addToIntersection(inter: var TIntersection, s: int) =
|
||||||
proc throws(tracked, n, orig: PNode) =
|
proc throws(tracked, n, orig: PNode) =
|
||||||
if n.typ == nil or n.typ.kind != tyError:
|
if n.typ == nil or n.typ.kind != tyError:
|
||||||
if orig != nil:
|
if orig != nil:
|
||||||
let x = copyNode(n)
|
let x = copyTree(orig)
|
||||||
x.info = orig.info
|
x.typ = n.typ
|
||||||
tracked.add x
|
tracked.add x
|
||||||
else:
|
else:
|
||||||
tracked.add n
|
tracked.add n
|
||||||
|
|
@ -329,7 +329,7 @@ proc createTag(g: ModuleGraph; n: PNode): PNode =
|
||||||
if not n.isNil: result.info = n.info
|
if not n.isNil: result.info = n.info
|
||||||
|
|
||||||
proc addRaiseEffect(a: PEffects, e, comesFrom: PNode) =
|
proc addRaiseEffect(a: PEffects, e, comesFrom: PNode) =
|
||||||
assert e.kind != nkRaiseStmt
|
#assert e.kind != nkRaiseStmt
|
||||||
var aa = a.exc
|
var aa = a.exc
|
||||||
for i in a.bottom..<aa.len:
|
for i in a.bottom..<aa.len:
|
||||||
# we only track the first node that can have the effect E in order
|
# we only track the first node that can have the effect E in order
|
||||||
|
|
@ -917,7 +917,7 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
if n[0].kind != nkEmpty:
|
if n[0].kind != nkEmpty:
|
||||||
n[0].info = n.info
|
n[0].info = n.info
|
||||||
#throws(tracked.exc, n[0])
|
#throws(tracked.exc, n[0])
|
||||||
addRaiseEffect(tracked, n[0], nil)
|
addRaiseEffect(tracked, n[0], n)
|
||||||
for i in 0..<n.safeLen:
|
for i in 0..<n.safeLen:
|
||||||
track(tracked, n[i])
|
track(tracked, n[i])
|
||||||
createTypeBoundOps(tracked, n[0].typ, n.info)
|
createTypeBoundOps(tracked, n[0].typ, n.info)
|
||||||
|
|
@ -1163,7 +1163,9 @@ proc checkRaisesSpec(g: ModuleGraph; spec, real: PNode, msg: string, hints: bool
|
||||||
break search
|
break search
|
||||||
# XXX call graph analysis would be nice here!
|
# XXX call graph analysis would be nice here!
|
||||||
pushInfoContext(g.config, spec.info)
|
pushInfoContext(g.config, spec.info)
|
||||||
localError(g.config, r.info, errGenerated, msg & typeToString(r.typ))
|
var rr = if r.kind == nkRaiseStmt: r[0] else: r
|
||||||
|
while rr.kind in {nkStmtList, nkStmtListExpr} and rr.len > 0: rr = rr.lastSon
|
||||||
|
localError(g.config, r.info, errGenerated, renderTree(rr) & " " & msg & typeToString(r.typ))
|
||||||
popInfoContext(g.config)
|
popInfoContext(g.config)
|
||||||
# hint about unnecessarily listed exception types:
|
# hint about unnecessarily listed exception types:
|
||||||
if hints:
|
if hints:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue