fix getting defined_names in a function