Skip to content

Commit

Permalink
Fix: don't track Defect in proc effect compatibility (#22037)
Browse files Browse the repository at this point in the history
  • Loading branch information
Menduist committed Jun 8, 2023
1 parent a8d0dda commit a4f9413
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 14 additions & 1 deletion compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,19 @@ proc compatibleEffectsAux(se, re: PNode): bool =
return false
result = true

proc isDefectException*(t: PType): bool
proc compatibleExceptions(se, re: PNode): bool =
if re.isNil: return false
for r in items(re):
block search:
if isDefectException(r.typ):
break search
for s in items(se):
if safeInheritanceDiff(r.typ, s.typ) <= 0:
break search
return false
result = true

proc hasIncompatibleEffect(se, re: PNode): bool =
if re.isNil: return false
for r in items(re):
Expand Down Expand Up @@ -1472,7 +1485,7 @@ proc compatibleEffects*(formal, actual: PType): EffectsCompat =
if not isNil(se) and se.kind != nkArgList:
# spec requires some exception or tag, but we don't know anything:
if real.len == 0: return efRaisesUnknown
let res = compatibleEffectsAux(se, real[exceptionEffects])
let res = compatibleExceptions(se, real[exceptionEffects])
if not res: return efRaisesDiffer

let st = spec[tagEffects]
Expand Down
5 changes: 5 additions & 0 deletions tests/effects/teffects1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ proc lier(): int {.raises: [IO2Error].} = #[tt.Hint
proc forw: int =
raise newException(IOError, "arg")

block:
proc someProc(t: string) {.raises: [Defect].} =
discard
let vh: proc(topic: string) {.raises: [].} = someProc

{.push raises: [Defect].}

type
Expand Down

0 comments on commit a4f9413

Please sign in to comment.