equality check on NimSym has now support in the VM; refs #6139

This commit is contained in:
Araq
2017-09-03 01:15:40 +02:00
parent 2d8e97ee03
commit 7132b04f44
2 changed files with 27 additions and 1 deletions

View File

@@ -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.

View File

@@ -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"