84
84
gcUnsafe, isRecursive, isTopLevel, hasSideEffect, inEnforcedGcSafe: bool
85
85
isInnerProc: bool
86
86
inEnforcedNoSideEffects: bool
87
+ unknownRaises: seq [(PSym, TLineInfo)]
87
88
currOptions: TOptions
88
89
optionsStack: seq [(TOptions, TNoteKinds)]
89
90
config: ConfigRef
@@ -639,6 +640,8 @@ proc importedFromC(n: PNode): bool =
639
640
proc propagateEffects(tracked: PEffects, n: PNode, s: PSym) =
640
641
let pragma = s.ast[pragmasPos]
641
642
let spec = effectSpec(pragma, wRaises)
643
+ if spec.isNil and sfForward in s.flags:
644
+ tracked.unknownRaises.add (s, n.info)
642
645
mergeRaises(tracked, spec, n)
643
646
644
647
let tagSpec = effectSpec(pragma, wTags)
@@ -1506,7 +1509,7 @@ proc subtypeRelation(g: ModuleGraph; spec, real: PNode): bool =
1506
1509
1507
1510
proc checkRaisesSpec(g: ModuleGraph; emitWarnings: bool ; spec, real: PNode, msg: string , hints: bool ;
1508
1511
effectPredicate: proc (g: ModuleGraph; a, b: PNode): bool {.nimcall.};
1509
- hintsArg: PNode = nil ; isForbids: bool = false ) =
1512
+ hintsArg: PNode = nil ; isForbids: bool = false ; unknownRaises: seq [(PSym, TLineInfo)] = @ [] ) =
1510
1513
# check that any real exception is listed in 'spec'; mark those as used;
1511
1514
# report any unused exception
1512
1515
var used = initIntSet()
@@ -1523,6 +1526,8 @@ proc checkRaisesSpec(g: ModuleGraph; emitWarnings: bool; spec, real: PNode, msg:
1523
1526
pushInfoContext(g.config, spec.info)
1524
1527
var rr = if r.kind == nkRaiseStmt: r[0 ] else : r
1525
1528
while rr.kind in {nkStmtList, nkStmtListExpr} and rr.len > 0 : rr = rr.lastSon
1529
+ for (s, info) in unknownRaises.items:
1530
+ message(g.config, info, hintUnknownRaises, s.name.s)
1526
1531
message(g.config, r.info, if emitWarnings: warnEffect else : errGenerated,
1527
1532
renderTree(rr) & " " & msg & typeToString(r.typ))
1528
1533
popInfoContext(g.config)
@@ -1680,7 +1685,7 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
1680
1685
if not isNil(raisesSpec):
1681
1686
let useWarning = s.name.s == " =destroy"
1682
1687
checkRaisesSpec(g, useWarning, raisesSpec, t.exc, " can raise an unlisted exception: " ,
1683
- hints= on , subtypeRelation, hintsArg= s.ast[0 ])
1688
+ hints= on , subtypeRelation, hintsArg= s.ast[0 ], unknownRaises = t.unknownRaises )
1684
1689
# after the check, use the formal spec:
1685
1690
effects[exceptionEffects] = raisesSpec
1686
1691
else :
0 commit comments