From 776455661ce1e75d308bc9afe21dc399c602fc08 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Mon, 16 May 2011 15:13:28 +0400 Subject: [PATCH] Fixed bug in scoping rules for references in default function argument values (PY-3550) --- .../python/codeInsight/dataflow/scope/ScopeUtil.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/ScopeUtil.java b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/ScopeUtil.java index db362f5e6e2d..5c769e20a430 100644 --- a/python/src/com/jetbrains/python/codeInsight/dataflow/scope/ScopeUtil.java +++ b/python/src/com/jetbrains/python/codeInsight/dataflow/scope/ScopeUtil.java @@ -46,8 +46,14 @@ public class ScopeUtil { @Nullable public static ScopeOwner getDeclarationScopeOwner(PyReferenceExpression node) { final String name = node.getName(); + PsiElement element = node; if (name != null) { - ScopeOwner owner = PsiTreeUtil.getParentOfType(node, ScopeOwner.class); + // References in default values of parameters are defined somewhere in outer scopes + if (PsiTreeUtil.getParentOfType(node, PyParameter.class) != null) { + element = PsiTreeUtil.getParentOfType(node, ScopeOwner.class); + } + + ScopeOwner owner = PsiTreeUtil.getParentOfType(element, ScopeOwner.class); while (owner != null) { Scope scope = ControlFlowCache.getScope(owner); if (scope.containsDeclaration(name)) {