From 66d3d459d3cdd907ca8ae5b528da5922edd6732f Mon Sep 17 00:00:00 2001 From: Mikhail Arkhipov Date: Wed, 25 Sep 2019 21:48:55 -0700 Subject: [PATCH] Fix find references --- src/Analysis/Ast/Impl/Analyzer/Handlers/FromImportHandler.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Analysis/Ast/Impl/Analyzer/Handlers/FromImportHandler.cs b/src/Analysis/Ast/Impl/Analyzer/Handlers/FromImportHandler.cs index 7975f97d2..b972b0023 100644 --- a/src/Analysis/Ast/Impl/Analyzer/Handlers/FromImportHandler.cs +++ b/src/Analysis/Ast/Impl/Analyzer/Handlers/FromImportHandler.cs @@ -105,8 +105,11 @@ private void DeclareVariable(PythonVariableModule variableModule, string memberN // First try imports since child modules should win, i.e. in 'from a.b import c' // 'c' should be a submodule if 'b' has one, even if 'b' also declares 'c = 1'. var value = GetValueFromImports(variableModule, imports as IImportChildrenSource, memberName); - // Now try exported + // First try exported or child submodules. value = value ?? variableModule.GetMember(memberName); + // Value may be variable or submodule. If it is variable, we need it in order to add reference. + var variable = variableModule.Analysis?.GlobalScope?.Variables[memberName]; + value = variable?.Value == value ? variable : value; // If nothing is exported, variables are still accessible. value = value ?? variableModule.Analysis?.GlobalScope?.Variables[memberName]?.Value ?? Eval.UnknownType; // Do not allow imported variables to override local declarations