summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/core/macros.nim3
-rw-r--r--tests/gensym/tgensymgeneric.nim25
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim
index a7d31ad62..3cfefb5c1 100644
--- a/lib/core/macros.nim
+++ b/lib/core/macros.nim
@@ -150,6 +150,9 @@ proc `==`*(a, b: NimIdent): bool {.magic: "EqIdent", noSideEffect.}
 proc `==`*(a, b: NimNode): bool {.magic: "EqNimrodNode", noSideEffect.}
   ## compares two Nim nodes
 
+proc `==`*(a, b: NimSym): bool {.magic: "EqNimrodNode", noSideEffect.}
+  ## compares two Nim symbols
+
 proc sameType*(a, b: NimNode): bool {.magic: "SameNodeType", noSideEffect.} =
   ## compares two Nim nodes' types. Return true if the types are the same,
   ## eg. true when comparing alias with original type.
diff --git a/tests/gensym/tgensymgeneric.nim b/tests/gensym/tgensymgeneric.nim
index 54390a4ef..9963ba808 100644
--- a/tests/gensym/tgensymgeneric.nim
+++ b/tests/gensym/tgensymgeneric.nim
@@ -1,3 +1,7 @@
+discard """
+  output: '''true'''
+"""
+
 # We need to open the gensym'ed symbol again so that the instantiation
 # creates a fresh copy; but this is wrong the very first reason for gensym
 # is that scope rules cannot be used! So simply removing 'sfGenSym' does
@@ -28,4 +32,23 @@ var
 let x = gen(a)
 let y = gen(b)
 
-echo x.x, " ", y.x
+doAssert x.x == 123
+doAssert y.x == "abc"
+
+# test symbol equality
+
+import macros
+
+static:
+  let sym1   = genSym()
+  let sym2   = genSym()
+  let sym3   = sym1
+  let nimsym = sym1.symbol
+  doAssert sym1        == sym1
+  doAssert sym2        != sym3
+  doAssert sym2.symbol != sym3.symbol
+  doAssert sym3        == sym1
+  doAssert sym1.symbol == sym1.symbol
+  doAssert nimsym      == nimsym
+
+echo "true"