Fix resolving global variable reassignment

GitOrigin-RevId: 235f566771e9bd83c5b04e47c170501830b5c66a
This commit is contained in:
Semyon Proshev
2019-07-02 06:52:16 +03:00
committed by intellij-monorepo-bot
parent 3cb186667e
commit 77b461420d
4 changed files with 11 additions and 3 deletions
@@ -136,7 +136,7 @@ public class ScopeImpl implements Scope {
if (myNamedElements == null || myImportedNameDefiners == null) {
collectDeclarations();
}
if (isNonlocal(name)) {
if (isNonlocal(name) || isGlobal(name)) {
return false;
}
if (!getNamedElements(name, true).isEmpty()) {
@@ -270,7 +270,7 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
final ScopeOwner resolvedOwner = processor.getOwner();
final Collection<PsiElement> resolvedElements = processor.getElements();
if (resolvedOwner != null && !resolvedElements.isEmpty() && !ControlFlowCache.getScope(resolvedOwner).isGlobal(referencedName)) {
if (resolvedOwner != null && !resolvedElements.isEmpty()) {
if (resolvedOwner == referenceOwner) {
final List<Instruction> instructions = getLatestDefinitions(referencedName, resolvedOwner, realContext);
// TODO: Use the results from the processor as a cache for resolving to latest defs
@@ -0,0 +1,4 @@
def f():
global xx
xx = 2
# <ref>
@@ -754,11 +754,15 @@ public class PyResolveTest extends PyResolveTestCase {
assertEquals("2", target.getText());
}
public void testGlobalNotDefinedAtTopLevel() {
assertResolvesTo(PyTargetExpression.class, "foo");
}
public void testGlobalReassignmentNotDefinedAtTopLevel() {
final PyTargetExpression target = assertResolvesTo(PyTargetExpression.class, "xx");
assertInstanceOf(target.getParent(), PyGlobalStatement.class);
}
// PY-13734
public void testImplicitDunderClass() {
assertUnresolved();