summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTanguy <tanguy@status.im>2023-06-08 14:09:06 +0200
committerGitHub <noreply@github.com>2023-06-08 14:09:06 +0200
commita4f9413a65b7aa77717bdad12156f92abe9ac2ed (patch)
tree6f4f266f937f7d7b40f4c5c30579e24a93cdc572
parenta8d0dda8333f78dfa427e0808ff84280363355d4 (diff)
downloadNim-a4f9413a65b7aa77717bdad12156f92abe9ac2ed.tar.gz
Fix: don't track Defect in proc effect compatibility (#22037)
-rw-r--r--compiler/types.nim15
-rw-r--r--tests/effects/teffects1.nim5
2 files changed, 19 insertions, 1 deletions
diff --git a/compiler/types.nim b/compiler/types.nim
index 10a39b0a7..353c445a6 100644
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -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):
@@ -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]
diff --git a/tests/effects/teffects1.nim b/tests/effects/teffects1.nim
index caa8907c3..49c904029 100644
--- a/tests/effects/teffects1.nim
+++ b/tests/effects/teffects1.nim
@@ -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