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

Commit 18e25f1

Browse files
Merge pull request #280 from AlexanderSher/Fix95
Several bug fixes
2 parents 62a7e8c + c4de2cd commit 18e25f1

19 files changed

+200
-204
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,14 @@ private bool TryImportModule(string modName, bool forceAbsolute, out ModuleRefer
441441
if (gotAllParents && ProjectState.Modules.TryImport(name, out modRef)) {
442442
moduleRef = modRef;
443443
(lastParent as BuiltinModule)?.AddChildModule(remainingParts[0], moduleRef.AnalysisModule);
444-
_unit.DeclaringModule.AddModuleReference(moduleRef);
444+
_unit.DeclaringModule.AddModuleReference(modName, moduleRef);
445445
remainingParts = null;
446446
return true;
447447
}
448448
}
449449

450450
if (moduleRef?.Module != null) {
451-
_unit.DeclaringModule.AddModuleReference(moduleRef);
451+
_unit.DeclaringModule.AddModuleReference(modName, moduleRef);
452452
return true;
453453
}
454454
return false;

src/Analysis/Engine/Impl/Infrastructure/Check.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ public static void FieldType<T>(string fieldName, object fieldValue) {
1717

1818
[DebuggerStepThrough]
1919
public static void ArgumentOfType<T>(string argumentName, object argument, [CallerMemberName] string callerName = null) {
20-
ArgumentNull(argumentName, argument);
20+
ArgumentNotNull(argumentName, argument);
2121

2222
if (!(argument is T)) {
2323
throw new ArgumentException($"Argument {argumentName} of method {callerName} must be of type {typeof(T)}");
2424
}
2525
}
2626

2727
[DebuggerStepThrough]
28-
public static void ArgumentNull(string argumentName, object argument) {
28+
public static void ArgumentNotNull(string argumentName, object argument) {
2929
if (argument is null) {
3030
throw new ArgumentNullException(argumentName);
3131
}
3232
}
3333

3434
[DebuggerStepThrough]
3535
public static void ArgumentNotNullOrEmpty(string argumentName, string argument) {
36-
ArgumentNull(argumentName, argument);
36+
ArgumentNotNull(argumentName, argument);
3737

3838
if (string.IsNullOrEmpty(argument)) {
3939
throw new ArgumentException(argumentName);

src/Analysis/Engine/Impl/Infrastructure/Disposable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class Disposable {
3030
/// <returns>The disposable object that runs the given action upon disposal.</returns>
3131
/// <exception cref="T:System.ArgumentNullException"><paramref name="dispose" /> is null.</exception>
3232
public static IDisposable Create(Action dispose) {
33-
Check.ArgumentNull(nameof(dispose), dispose);
33+
Check.ArgumentNotNull(nameof(dispose), dispose);
3434
return new AnonymousDisposable(dispose);
3535
}
3636

@@ -41,7 +41,7 @@ public static IDisposable Create(Action dispose) {
4141
/// <returns>The disposable object that disposes wrapped object.</returns>
4242
/// <exception cref="T:System.ArgumentNullException"><paramref name="disposable" /> is null.</exception>
4343
public static IDisposable Create(IDisposable disposable) {
44-
Check.ArgumentNull(nameof(disposable), disposable);
44+
Check.ArgumentNotNull(nameof(disposable), disposable);
4545
return new DisposableWrapper(disposable);
4646
}
4747

src/Analysis/Engine/Impl/MemberResult.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,17 @@ private PythonMemberType GetMemberType() {
160160
return result;
161161
}
162162

163-
public override bool Equals(object obj) {
164-
if (!(obj is MemberResult)) {
165-
return false;
163+
public bool Equals(MemberResult other) => string.Equals(Name, other.Name) && Equals(Scope, other.Scope);
164+
165+
public override bool Equals(object obj) => obj is MemberResult other && Equals(other);
166+
167+
public override int GetHashCode() {
168+
unchecked {
169+
return ((Name != null ? Name.GetHashCode() : 0) * 397) ^ (Scope != null ? Scope.GetHashCode() : 0);
166170
}
167-
return Name == ((MemberResult)obj).Name;
168171
}
169172

170-
public static bool operator ==(MemberResult x, MemberResult y) => x.Name == y.Name;
171-
public static bool operator !=(MemberResult x, MemberResult y) => x.Name != y.Name;
172-
public override int GetHashCode() => Name.GetHashCode();
173+
public static bool operator ==(MemberResult left, MemberResult right) => left.Equals(right);
174+
public static bool operator !=(MemberResult left, MemberResult right) => !left.Equals(right);
173175
}
174176
}

src/Analysis/Engine/Impl/Parsing/Ast/DottedName.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@ namespace Microsoft.PythonTools.Parsing.Ast {
2222
public class DottedName : Node {
2323
private readonly NameExpression[] _names;
2424

25-
public DottedName(NameExpression[] names) {
25+
public DottedName(NameExpression[]/*!*/ names) {
2626
_names = names;
2727
}
2828

29-
public IList<NameExpression> Names {
30-
get { return _names; }
31-
}
29+
public IList<NameExpression> Names => _names;
3230

3331
public virtual string MakeString() {
34-
if (_names.Length == 0) return String.Empty;
32+
if (_names.Length == 0) return string.Empty;
3533

3634
StringBuilder ret = new StringBuilder(_names[0].Name);
3735
for (int i = 1; i < _names.Length; i++) {

src/Analysis/Engine/Impl/Parsing/Ast/FromImportStatement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class FromImportStatement : Statement {
2525
private static readonly string[] _star = new[] { "*" };
2626
private PythonVariable[] _variables;
2727

28-
public FromImportStatement(ModuleName root, NameExpression/*!*/[] names, NameExpression[] asNames, bool fromFuture, bool forceAbsolute, int importIndex) {
28+
public FromImportStatement(ModuleName/*!*/ root, NameExpression/*!*/[] names, NameExpression[] asNames, bool fromFuture, bool forceAbsolute, int importIndex) {
2929
Root = root;
3030
Names = names;
3131
AsNames = asNames;

src/Analysis/Engine/Impl/Parsing/Ast/ModuleName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace Microsoft.PythonTools.Parsing.Ast {
1818
public class ModuleName : DottedName {
19-
public ModuleName(NameExpression[] names)
19+
public ModuleName(NameExpression[]/*!*/ names)
2020
: base(names) {
2121
}
2222
}

src/Analysis/Engine/Impl/Parsing/Ast/RelativeModuleName.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,18 @@
1818

1919
namespace Microsoft.PythonTools.Parsing.Ast {
2020
public class RelativeModuleName : ModuleName {
21-
private readonly int _dotCount;
22-
23-
public RelativeModuleName(NameExpression[] names, int dotCount)
21+
public RelativeModuleName(NameExpression[]/*!*/ names, int dotCount)
2422
: base(names) {
25-
_dotCount = dotCount;
23+
DotCount = dotCount;
2624
}
2725

28-
public override string MakeString() {
29-
return new string('.', DotCount) + base.MakeString();
30-
}
26+
public override string MakeString() => new string('.', DotCount) + base.MakeString();
3127

32-
public int DotCount {
33-
get {
34-
return _dotCount;
35-
}
36-
}
28+
public int DotCount { get; }
3729

3830
internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
3931
var whitespace = this.GetListWhiteSpace(ast);
40-
for (int i = 0; i < _dotCount; i++) {
32+
for (int i = 0; i < DotCount; i++) {
4133
if (whitespace != null) {
4234
res.Append(whitespace[i]);
4335
}

src/Analysis/Engine/Impl/ProjectEntry.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ private void Parse(bool enqueueOnly, CancellationToken cancel) {
268268
MyScope.Scope.ClearNodeValues();
269269
MyScope.Scope.ClearLinkedVariables();
270270
MyScope.Scope.ClearVariables();
271+
MyScope.ClearReferencedModules();
271272
MyScope.ClearUnresolvedModules();
272273
_unit.State.ClearDiagnostics(this);
273274

@@ -366,10 +367,7 @@ public void Dispose() {
366367
}
367368
}
368369

369-
foreach (var moduleReference in MyScope.ModuleReferences.ToList()) {
370-
MyScope.RemoveModuleReference(moduleReference);
371-
}
372-
370+
MyScope.ClearReferencedModules();
373371
NewParseTree -= NewParseTree;
374372
NewAnalysis -= NewAnalysis;
375373
}

0 commit comments

Comments
 (0)