diff options
author | cooldome <cdome@bk.ru> | 2018-11-21 20:30:03 +0000 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-11-21 21:30:03 +0100 |
commit | 086676782a6053158cc6da14bc65961205c4b014 (patch) | |
tree | 4f599c3f2dd615bc4065f61df8ece68ca21a4afe /tests/macros/tgetimpl.nim | |
parent | 1cc8b7814d3a744a384d42b0f9f5a3bc65e39fe9 (diff) | |
download | Nim-086676782a6053158cc6da14bc65961205c4b014.tar.gz |
Add isInstanceOf for generic procs to the macros module (#9730)
Diffstat (limited to 'tests/macros/tgetimpl.nim')
-rw-r--r-- | tests/macros/tgetimpl.nim | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/macros/tgetimpl.nim b/tests/macros/tgetimpl.nim index a546271ff..aacfb703e 100644 --- a/tests/macros/tgetimpl.nim +++ b/tests/macros/tgetimpl.nim @@ -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) + |