From 1a0417fbe0d2fe61c05a68f14858b0da0e596c02 Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Wed, 1 Jul 2015 20:11:09 +0200 Subject: macros: Introduce sameType(a, b) for node types Previously introduced node comparison `==` was working somehow wrong on nodes returned from getType(a), comparing just ids of the symbols. Recently introduced `==` change 47dce2688633fad840a2f5e4073c531f1cd640ca started comparing symbol nodes pointer-wise, thus strictly. Since getType(a) always creates new symbol pointing to the type, comparing two such nodes using `==` always returns false, even they point to the same type. That is why we need a new sameType macro to be able to tell if these nodes point to the same type. --- lib/core/macros.nim | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 044020b2a..49def06f0 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -144,6 +144,10 @@ proc `==`*(a, b: NimIdent): bool {.magic: "EqIdent", noSideEffect.} proc `==`*(a, b: NimNode): bool {.magic: "EqNimrodNode", noSideEffect.} ## compares two Nim nodes +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. + proc len*(n: NimNode): int {.magic: "NLen", noSideEffect.} ## returns the number of children of `n`. -- cgit 1.4.1-2-gfad0