resolve works correctly in nested comprehensions (temp fix until parser is rewritten) (PY-3068)

This commit is contained in:
Dmitry Jemerov
2011-03-13 16:44:43 +01:00
parent d64d1bf236
commit 588726541b
3 changed files with 13 additions and 2 deletions
@@ -147,8 +147,12 @@ public class PyResolveUtil {
if ((roof != null) && (seeker != null) && !PsiTreeUtil.isAncestor(roof, seeker, false)) return null;
// maybe we're capped by a class? param lists are not capped though syntactically inside the function.
if (is_outside_param_list && refersFromMethodToClass(capFunction, seeker)) continue;
// names defined in a comprehension element are only visible inside it
if (seeker instanceof PyComprehensionElement && !PsiTreeUtil.isAncestor(seeker, elt, false)) continue;
// names defined in a comprehension element are only visible inside it or the list comp expressions directly above it
if (seeker instanceof PyComprehensionElement &&
!(seeker.getParent() instanceof PyComprehensionElement) &&
!PsiTreeUtil.isAncestor(seeker, elt, false)) {
continue;
}
// check what we got
if (seeker != null) {
if (!processor.execute(seeker, ResolveState.initial())) {
@@ -0,0 +1,3 @@
lst1 = [[1,2,3],[4,5,6],[7,8,9]]
lst2 = [xx for yy in lst1 for xx in yy]
# <ref>
@@ -405,4 +405,8 @@ public class PyResolveTest extends PyResolveTestCase {
public void testResolveInGenerator() {
assertResolvesTo(PyTargetExpression.class, "foo");
}
public void testNestedListComp() { // PY-3068
assertResolvesTo(PyTargetExpression.class, "yy");
}
}