[ty] fix global symbol lookup from eager scopes by mtshiba · Pull Request #21317 · astral-sh/ruff (original) (raw)
Summary
cf. #20962
In the following code, foo in the comprehension was not reported as unresolved:
error: [unresolved-reference] "Name foo used when not defined"
foo foo = [ # no error! # revealed: Divergent reveal_type(x) for _ in () for x in [foo] ]
baz = [
# error: [unresolved-reference] "Name baz used when not defined"
# revealed: Unknown
reveal_type(x) for _ in () for x in [baz]
]
In fact, this is a more serious bug than it looks: for foo, explicit_global_symbol is called, causing a symbol that should actually be Undefined to be reported as being of type Divergent.
This PR fixes this bug. As a result, the code in mdtest/regression/pr_20962_comprehension_panics.md no longer panics.
Test Plan
corpus\cyclic_symbol_in_comprehension.py is added.
New tests are added in mdtest/comprehensions/basic.md.