Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 04966be

Browse files
author
MikhailArkhipov
committed
2 parents a07a5bc + 291b59d commit 04966be

7 files changed

Lines changed: 1969 additions & 1860 deletions

File tree

src/Analysis/Engine/Impl/Analyzer/DDG.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,13 @@ private bool TryImportModule(string modName, bool forceAbsolute, out ModuleRefer
454454
return false;
455455
}
456456

457-
internal List<AnalysisValue> LookupBaseMethods(string name, IEnumerable<IAnalysisSet> bases, Node node, AnalysisUnit unit) {
457+
internal List<AnalysisValue> LookupBaseMethods(string name, IEnumerable<IAnalysisSet> mro, Node node, AnalysisUnit unit) {
458458
var result = new List<AnalysisValue>();
459-
foreach (var b in bases) {
460-
foreach (var curType in b) {
461-
var klass = curType as BuiltinClassInfo;
462-
if (klass != null) {
463-
var value = klass.GetMember(node, unit, name);
459+
foreach (var @class in mro.Skip(1)) {
460+
foreach (var curType in @class) {
461+
bool isClass = curType is ClassInfo || curType is BuiltinClassInfo;
462+
if (isClass) {
463+
var value = curType.GetMember(node, unit, name);
464464
if (value != null) {
465465
result.AddRange(value);
466466
}
@@ -470,7 +470,6 @@ internal List<AnalysisValue> LookupBaseMethods(string name, IEnumerable<IAnalysi
470470
return result;
471471
}
472472

473-
474473
public override bool Walk(FunctionDefinition node) {
475474
InterpreterScope funcScope;
476475
if (_unit.InterpreterScope.TryGetNodeScope(node, out funcScope)) {
@@ -572,9 +571,28 @@ public override bool Walk(ImportStatement node) {
572571

573572
public override bool Walk(ReturnStatement node) {
574573
var fnScope = CurrentFunction;
575-
if (node.Expression != null && fnScope != null) {
576-
var lookupRes = _eval.Evaluate(node.Expression);
577-
fnScope.AddReturnTypes(node, _unit, lookupRes);
574+
if (fnScope == null || node.Expression == null) {
575+
return true;
576+
}
577+
578+
var lookupRes = _eval.Evaluate(node.Expression);
579+
fnScope.AddReturnTypes(node, _unit, lookupRes);
580+
581+
var function = fnScope.Function;
582+
var analysisUnit = (FunctionAnalysisUnit)function.AnalysisUnit;
583+
584+
if (Scope.OuterScope is ClassScope curClass) {
585+
var bases = LookupBaseMethods(
586+
analysisUnit.Ast.Name,
587+
curClass.Class.Mro,
588+
analysisUnit.Ast,
589+
analysisUnit
590+
);
591+
592+
foreach (FunctionInfo baseFunction in bases.OfType<FunctionInfo>()) {
593+
var baseAnalysisUnit = (FunctionAnalysisUnit)baseFunction.AnalysisUnit;
594+
baseAnalysisUnit.ReturnValue.AddTypes(_unit, lookupRes);
595+
}
578596
}
579597
return true;
580598
}

src/Analysis/Engine/Impl/Microsoft.Python.Analysis.Engine.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<AssemblyName>Microsoft.Python.Analysis.Engine</AssemblyName>
66
</PropertyGroup>
77
<PropertyGroup>
8-
<!--
8+
<!--
99
1701, 1702 - "You may need to supply assembly policy"
1010
1998 - "This async method lacks 'await'"
1111
-->
1212
<NoWarn>1701;1702;1998;$(NoWarn)</NoWarn>
1313
</PropertyGroup>
14-
<Import Project="..\..\..\..\Build\NetStandard.settings" />
14+
<Import Project="..\..\..\..\build\NetStandard.settings" />
1515
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
1616
<ItemGroup>
1717
<PackageReference Include="MicroBuild.Core" Version="0.3.0">
@@ -47,5 +47,5 @@
4747
</EmbeddedResource>
4848
</ItemGroup>
4949
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
50-
<Import Project="..\..\..\..\Build\NetStandard.targets" />
51-
</Project>
50+
<Import Project="..\..\..\..\build\NetStandard.targets" />
51+
</Project>

0 commit comments

Comments
 (0)