Fix env extension bug in macro/function application