summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-10-26 22:19:05 +0200
committerGitHub <noreply@github.com>2020-10-26 22:19:05 +0200
commit3bdc0005211b0d543e0ff48ccf6bc5a9f2a2a30b (patch)
treed17e520691de67784767dafd103357233b46959d
parentcf01945f54f099c268850c720986ad6c9bbdb51e (diff)
downloadNim-3bdc0005211b0d543e0ff48ccf6bc5a9f2a2a30b.tar.gz
[backport] fix #15595 procvar `==` works in VM (#15724)
-rw-r--r--compiler/vm.nim6
-rw-r--r--tests/vm/tvmmisc.nim24
2 files changed, 28 insertions, 2 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim
index ac2feac26..761186dc3 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -994,8 +994,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
         let nb = regs[rb].node
         let nc = regs[rc].node
         if nb.kind != nc.kind: discard
-        elif (nb == nc) or (nb.kind == nkNilLit): ret = true
-        elif nb.kind == nkIntLit and nb.intVal == nc.intVal: # TODO: nkPtrLit
+        elif (nb == nc) or (nb.kind == nkNilLit): ret = true # intentional
+        elif sameConstant(nb, nc): ret = true
+          # this also takes care of procvar's, represented as nkTupleConstr, eg (nil, nil)
+        elif nb.kind == nkIntLit and nc.kind == nkIntLit and nb.intVal == nc.intVal: # TODO: nkPtrLit
           let tb = nb.getTyp
           let tc = nc.getTyp
           ret = tb.kind in PtrLikeKinds and tc.kind == tb.kind
diff --git a/tests/vm/tvmmisc.nim b/tests/vm/tvmmisc.nim
index f05bb6dec..e4d6c308f 100644
--- a/tests/vm/tvmmisc.nim
+++ b/tests/vm/tvmmisc.nim
@@ -205,6 +205,30 @@ block: # bug #13081
   static:
     doAssert j1.x1 == 12
 
+block: # bug #15595
+  proc fn0()=echo 0
+  proc fn1()=discard
+  proc main=
+    var local = 0
+    proc fn2()=echo local
+    var a0 = fn0
+    var a1 = fn1
+    var a2 = fn2
+    var a3: proc()
+    var a4: proc()
+    doAssert a0 == fn0 # bugfix
+    doAssert a1 == fn1 # ditto
+    doAssert a2 == fn2 # ditto
+
+    doAssert fn0 != fn1
+
+    doAssert a2 != nil
+    doAssert a3 == nil # bugfix
+
+    doAssert a3 == a4 # bugfix
+  static: main()
+  main()
+
 # bug #15363
 import sequtils