'assert' hides EAssertionFailsure; stdlib makes use of 'tags'
This commit is contained in:
parent
7f6633a06f
commit
3c0a6a8962
16 changed files with 242 additions and 161 deletions
|
|
@ -59,6 +59,7 @@ proc InitDefines*() =
|
|||
DefineSymbol("nimhygiene")
|
||||
DefineSymbol("niminheritable")
|
||||
DefineSymbol("nimmixin")
|
||||
DefineSymbol("nimeffects")
|
||||
|
||||
# add platform specific symbols:
|
||||
case targetCPU
|
||||
|
|
|
|||
|
|
@ -102,7 +102,8 @@ proc addEffect(a: PEffects, e: PNode, useLineInfo=true) =
|
|||
throws(a.exc, e)
|
||||
|
||||
proc mergeEffects(a: PEffects, b: PNode, useLineInfo: bool) =
|
||||
for effect in items(b): addEffect(a, effect, useLineInfo)
|
||||
if not b.isNil:
|
||||
for effect in items(b): addEffect(a, effect, useLineInfo)
|
||||
|
||||
proc addTag(a: PEffects, e: PNode, useLineInfo=true) =
|
||||
var aa = a.tags
|
||||
|
|
@ -113,7 +114,8 @@ proc addTag(a: PEffects, e: PNode, useLineInfo=true) =
|
|||
throws(a.tags, e)
|
||||
|
||||
proc mergeTags(a: PEffects, b: PNode, useLineInfo: bool) =
|
||||
for effect in items(b): addTag(a, effect, useLineInfo)
|
||||
if not b.isNil:
|
||||
for effect in items(b): addTag(a, effect, useLineInfo)
|
||||
|
||||
proc listEffects(a: PEffects) =
|
||||
for e in items(a.exc): Message(e.info, hintUser, typeToString(e.typ))
|
||||
|
|
@ -125,7 +127,7 @@ proc catches(tracked: PEffects, e: PType) =
|
|||
var i = tracked.bottom
|
||||
while i < L:
|
||||
# r supertype of e?
|
||||
if inheritanceDiff(tracked.exc[i].excType, e) <= 0:
|
||||
if safeInheritanceDiff(tracked.exc[i].excType, e) <= 0:
|
||||
tracked.exc.sons[i] = tracked.exc.sons[L-1]
|
||||
dec L
|
||||
else:
|
||||
|
|
@ -272,7 +274,7 @@ proc checkRaisesSpec(spec, real: PNode, msg: string, hints: bool) =
|
|||
for r in items(real):
|
||||
block search:
|
||||
for s in 0 .. <spec.len:
|
||||
if inheritanceDiff(r.excType, spec[s].typ) <= 0:
|
||||
if safeInheritanceDiff(r.excType, spec[s].typ) <= 0:
|
||||
used.incl(s)
|
||||
break search
|
||||
# XXX call graph analysis would be nice here!
|
||||
|
|
@ -341,6 +343,6 @@ proc trackProc*(s: PSym, body: PNode) =
|
|||
let tagsSpec = effectSpec(p, wTags)
|
||||
if not isNil(tagsSpec):
|
||||
checkRaisesSpec(tagsSpec, t.tags, "can have an unlisted effect: ",
|
||||
hints=on)
|
||||
hints=off)
|
||||
# after the check, use the formal spec:
|
||||
effects.sons[tagEffects] = tagsSpec
|
||||
|
|
|
|||
|
|
@ -1190,16 +1190,23 @@ proc baseOfDistinct*(t: PType): PType =
|
|||
internalAssert parent != nil
|
||||
parent.sons[0] = it.sons[0]
|
||||
|
||||
proc safeInheritanceDiff*(a, b: PType): int =
|
||||
# same as inheritanceDiff but checks for tyError:
|
||||
if a.kind == tyError or b.kind == tyError:
|
||||
result = -1
|
||||
else:
|
||||
result = inheritanceDiff(a, b)
|
||||
|
||||
proc compatibleEffectsAux(se, re: PNode): bool =
|
||||
if re.isNil: return false
|
||||
for r in items(re):
|
||||
block search:
|
||||
for s in items(se):
|
||||
if inheritanceDiff(r.typ, s.typ) <= 0:
|
||||
if safeInheritanceDiff(r.typ, s.typ) <= 0:
|
||||
break search
|
||||
return false
|
||||
result = true
|
||||
|
||||
|
||||
proc compatibleEffects*(formal, actual: PType): bool =
|
||||
# for proc type compatibility checking:
|
||||
assert formal.kind == tyProc and actual.kind == tyProc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue