Fix bug for vars declared via list comprehensions

This logic already exists for undefined identifiers in the global scope,
but it must be copied to the branch reserved for identifiers in function
scopes.
Consolidate branches

Because these two branches only differ by one line, they should be
consolidated.