fixed a bug in leaf codegen