fixed a gnarly and subtle bug triggered by:

def f(p, k):
    def g():
        print(k)
    if k == 0:
        f(g, 1)

f(None, 0)