Add isInstanceOf for generic procs to the macros module (#9730)
This commit is contained in:
parent
1cc8b7814d
commit
086676782a
8 changed files with 46 additions and 3 deletions
|
|
@ -46,3 +46,22 @@ static:
|
|||
doAssert isSameOwner(foo, poo)
|
||||
doAssert isSameOwner(foo, echo) == false
|
||||
doAssert isSameOwner(poo, len) == false
|
||||
|
||||
#---------------------------------------------------------------
|
||||
|
||||
macro check_gen_proc(ex: typed): (bool, bool) =
|
||||
let lenChoice = bindsym"len"
|
||||
var is_equal = false
|
||||
var is_instance_of = false
|
||||
for child in lenChoice:
|
||||
if not is_equal:
|
||||
is_equal = ex[0] == child
|
||||
if not is_instance_of:
|
||||
is_instance_of = isInstantiationOf(ex[0], child)
|
||||
|
||||
result = nnkTupleConstr.newTree(newLit(is_equal), newLit(is_instance_of))
|
||||
|
||||
# check that len(seq[int]) is not equal to bindSym"len", but is instance of it
|
||||
let a = @[1,2,3]
|
||||
assert: check_gen_proc(len(a)) == (false, true)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue