mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
equality check on NimSym has now support in the VM; refs #6139
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user