Templating: added error for maximum recursion
tests/codegen: adapted and added tests