summary refs log tree commit diff stats
path: root/compiler/semmagic.nim
diff options
context:
space:
mode:
authorcooldome <ariabushenko@gmail.com>2020-11-09 10:47:29 +0000
committerGitHub <noreply@github.com>2020-11-09 11:47:29 +0100
commit7b192177984d77355ce67f8cfa4aee227be73e7b (patch)
tree30c5bdebe735347754015dba40ecf5d92eb725d8 /compiler/semmagic.nim
parent673c5990c6b2130dd3b1a4854eb5d85c73a90cd0 (diff)
downloadNim-7b192177984d77355ce67f8cfa4aee227be73e7b.tar.gz
fix #15707 (#15870)
Diffstat (limited to 'compiler/semmagic.nim')
-rw-r--r--compiler/semmagic.nim26
1 files changed, 18 insertions, 8 deletions
diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim
index 5e6b4dbe2..3368bcfbf 100644
--- a/compiler/semmagic.nim
+++ b/compiler/semmagic.nim
@@ -527,14 +527,24 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
     if n[^1].kind == nkSym and n[^1].sym.kind notin {skProc, skFunc}:
       localError(c.config, n.info, "finalizer must be a direct reference to a proc")
     elif optTinyRtti in c.config.globalOptions:
-      let fin = if n[^1].kind in {nkLambda, nkDo}: n[^1][namePos].sym
-                else: n[^1].sym
-      # check if we converted this finalizer into a destructor already:
-      let t = whereToBindTypeHook(c, fin.typ[1].skipTypes(abstractInst+{tyRef}))
-      if t != nil and t.attachedOps[attachedDestructor] != nil and t.attachedOps[attachedDestructor].owner == fin:
-        discard "already turned this one into a finalizer"
-      else:
-        bindTypeHook(c, turnFinalizerIntoDestructor(c, fin, n.info), n, attachedDestructor)
+      let nfin = skipConvCastAndClosure(n[^1])
+      let fin = case nfin.kind 
+        of nkSym: nfin.sym
+        of nkLambda, nkDo: nfin[namePos].sym
+        else: 
+          localError(c.config, n.info, "finalizer must be a direct reference to a proc")
+          nil
+      if fin != nil:
+        if fin.kind notin {skProc, skFunc}:
+          # calling convention is checked in codegen
+          localError(c.config, n.info, "finalizer must be a direct reference to a proc")
+
+        # check if we converted this finalizer into a destructor already:
+        let t = whereToBindTypeHook(c, fin.typ[1].skipTypes(abstractInst+{tyRef}))
+        if t != nil and t.attachedOps[attachedDestructor] != nil and t.attachedOps[attachedDestructor].owner == fin:
+          discard "already turned this one into a finalizer"
+        else:
+          bindTypeHook(c, turnFinalizerIntoDestructor(c, fin, n.info), n, attachedDestructor)
     result = n
   of mDestroy:
     result = n