summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-06-25 11:15:36 +0200
committerAraq <rumpf_a@web.de>2015-06-25 11:42:27 +0200
commit47dce2688633fad840a2f5e4073c531f1cd640ca (patch)
treedf795dd43014ea0582f5a8beaadb9e58e5dfe719 /compiler
parente4c8e0aed0d2a04ca4260ea743523a0d394e5ac0 (diff)
downloadNim-47dce2688633fad840a2f5e4073c531f1cd640ca.tar.gz
fixes #2985
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semfold.nim3
-rw-r--r--compiler/trees.nim12
2 files changed, 11 insertions, 4 deletions
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index b83641706..9a0c856dc 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -437,6 +437,9 @@ proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
      mNLen..mNError, mEqRef, mSlurp, mStaticExec, mNGenSym, mSpawn,
      mParallel, mPlugin:
     discard
+  of mEqProc:
+    result = newIntNodeT(ord(
+        exprStructuralEquivalent(a, b, strictSymEquality=true)), n)
   else: internalError(a.info, "evalOp(" & $m & ')')
 
 proc getConstIfExpr(c: PSym, n: PNode): PNode =
diff --git a/compiler/trees.nim b/compiler/trees.nim
index 2c631af99..659df334b 100644
--- a/compiler/trees.nim
+++ b/compiler/trees.nim
@@ -36,15 +36,18 @@ proc cyclicTree*(n: PNode): bool =
   var s = newNodeI(nkEmpty, n.info)
   result = cyclicTreeAux(n, s)
 
-proc exprStructuralEquivalent*(a, b: PNode): bool =
+proc exprStructuralEquivalent*(a, b: PNode; strictSymEquality=false): bool =
   result = false
   if a == b:
     result = true
   elif (a != nil) and (b != nil) and (a.kind == b.kind):
     case a.kind
     of nkSym:
-      # don't go nuts here: same symbol as string is enough:
-      result = a.sym.name.id == b.sym.name.id
+      if strictSymEquality:
+        result = a.sym == b.sym
+      else:
+        # don't go nuts here: same symbol as string is enough:
+        result = a.sym.name.id == b.sym.name.id
     of nkIdent: result = a.ident.id == b.ident.id
     of nkCharLit..nkInt64Lit: result = a.intVal == b.intVal
     of nkFloatLit..nkFloat64Lit: result = a.floatVal == b.floatVal
@@ -53,7 +56,8 @@ proc exprStructuralEquivalent*(a, b: PNode): bool =
     else:
       if sonsLen(a) == sonsLen(b):
         for i in countup(0, sonsLen(a) - 1):
-          if not exprStructuralEquivalent(a.sons[i], b.sons[i]): return
+          if not exprStructuralEquivalent(a.sons[i], b.sons[i],
+                                          strictSymEquality): return
         result = true
 
 proc sameTree*(a, b: PNode): bool =