From 086676782a6053158cc6da14bc65961205c4b014 Mon Sep 17 00:00:00 2001 From: cooldome Date: Wed, 21 Nov 2018 20:30:03 +0000 Subject: Add isInstanceOf for generic procs to the macros module (#9730) --- tests/macros/tgetimpl.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/macros') 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) + -- cgit 1.4.1-2-gfad0