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

Several bug fixes #280

Merged
merged 2 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Analysis/Engine/Impl/Analyzer/DDG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,14 @@ private bool TryImportModule(string modName, bool forceAbsolute, out ModuleRefer
if (gotAllParents && ProjectState.Modules.TryImport(name, out modRef)) {
moduleRef = modRef;
(lastParent as BuiltinModule)?.AddChildModule(remainingParts[0], moduleRef.AnalysisModule);
_unit.DeclaringModule.AddModuleReference(moduleRef);
_unit.DeclaringModule.AddModuleReference(modName, moduleRef);
remainingParts = null;
return true;
}
}

if (moduleRef?.Module != null) {
_unit.DeclaringModule.AddModuleReference(moduleRef);
_unit.DeclaringModule.AddModuleReference(modName, moduleRef);
return true;
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/Analysis/Engine/Impl/Infrastructure/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ public static void FieldType<T>(string fieldName, object fieldValue) {

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

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

[DebuggerStepThrough]
public static void ArgumentNull(string argumentName, object argument) {
public static void ArgumentNotNull(string argumentName, object argument) {
if (argument is null) {
throw new ArgumentNullException(argumentName);
}
}

[DebuggerStepThrough]
public static void ArgumentNotNullOrEmpty(string argumentName, string argument) {
ArgumentNull(argumentName, argument);
ArgumentNotNull(argumentName, argument);

if (string.IsNullOrEmpty(argument)) {
throw new ArgumentException(argumentName);
Expand Down
4 changes: 2 additions & 2 deletions src/Analysis/Engine/Impl/Infrastructure/Disposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class Disposable {
/// <returns>The disposable object that runs the given action upon disposal.</returns>
/// <exception cref="T:System.ArgumentNullException"><paramref name="dispose" /> is null.</exception>
public static IDisposable Create(Action dispose) {
Check.ArgumentNull(nameof(dispose), dispose);
Check.ArgumentNotNull(nameof(dispose), dispose);
return new AnonymousDisposable(dispose);
}

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

Expand Down
16 changes: 9 additions & 7 deletions src/Analysis/Engine/Impl/MemberResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,17 @@ private PythonMemberType GetMemberType() {
return result;
}

public override bool Equals(object obj) {
if (!(obj is MemberResult)) {
return false;
public bool Equals(MemberResult other) => string.Equals(Name, other.Name) && Equals(Scope, other.Scope);

public override bool Equals(object obj) => obj is MemberResult other && Equals(other);

public override int GetHashCode() {
unchecked {
return ((Name != null ? Name.GetHashCode() : 0) * 397) ^ (Scope != null ? Scope.GetHashCode() : 0);
}
return Name == ((MemberResult)obj).Name;
}

public static bool operator ==(MemberResult x, MemberResult y) => x.Name == y.Name;
public static bool operator !=(MemberResult x, MemberResult y) => x.Name != y.Name;
public override int GetHashCode() => Name.GetHashCode();
public static bool operator ==(MemberResult left, MemberResult right) => left.Equals(right);
public static bool operator !=(MemberResult left, MemberResult right) => !left.Equals(right);
}
}
8 changes: 3 additions & 5 deletions src/Analysis/Engine/Impl/Parsing/Ast/DottedName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ namespace Microsoft.PythonTools.Parsing.Ast {
public class DottedName : Node {
private readonly NameExpression[] _names;

public DottedName(NameExpression[] names) {
public DottedName(NameExpression[]/*!*/ names) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of /*!*/ introduced in a few of these files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment that I've used to mark parameter that can't be null. I can add Check calls instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to change it, I just hadn't seen that before and was curious. Grepping through the project shows its use a number of other times as well (so I just hadn't noticed).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear - this is just a comment. It isn't handled by any analyzers. I really expect to see non-nullable reference types in C# 8: https://github.com/dotnet/csharplang/wiki/Nullable-Reference-Types-Preview

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I know. I actually went searching to see if that feature existed yet when you mentioned it. 🙂

_names = names;
}

public IList<NameExpression> Names {
get { return _names; }
}
public IList<NameExpression> Names => _names;

public virtual string MakeString() {
if (_names.Length == 0) return String.Empty;
if (_names.Length == 0) return string.Empty;

StringBuilder ret = new StringBuilder(_names[0].Name);
for (int i = 1; i < _names.Length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class FromImportStatement : Statement {
private static readonly string[] _star = new[] { "*" };
private PythonVariable[] _variables;

public FromImportStatement(ModuleName root, NameExpression/*!*/[] names, NameExpression[] asNames, bool fromFuture, bool forceAbsolute, int importIndex) {
public FromImportStatement(ModuleName/*!*/ root, NameExpression/*!*/[] names, NameExpression[] asNames, bool fromFuture, bool forceAbsolute, int importIndex) {
Root = root;
Names = names;
AsNames = asNames;
Expand Down
2 changes: 1 addition & 1 deletion src/Analysis/Engine/Impl/Parsing/Ast/ModuleName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Microsoft.PythonTools.Parsing.Ast {
public class ModuleName : DottedName {
public ModuleName(NameExpression[] names)
public ModuleName(NameExpression[]/*!*/ names)
: base(names) {
}
}
Expand Down
18 changes: 5 additions & 13 deletions src/Analysis/Engine/Impl/Parsing/Ast/RelativeModuleName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,18 @@

namespace Microsoft.PythonTools.Parsing.Ast {
public class RelativeModuleName : ModuleName {
private readonly int _dotCount;

public RelativeModuleName(NameExpression[] names, int dotCount)
public RelativeModuleName(NameExpression[]/*!*/ names, int dotCount)
: base(names) {
_dotCount = dotCount;
DotCount = dotCount;
}

public override string MakeString() {
return new string('.', DotCount) + base.MakeString();
}
public override string MakeString() => new string('.', DotCount) + base.MakeString();

public int DotCount {
get {
return _dotCount;
}
}
public int DotCount { get; }

internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) {
var whitespace = this.GetListWhiteSpace(ast);
for (int i = 0; i < _dotCount; i++) {
for (int i = 0; i < DotCount; i++) {
if (whitespace != null) {
res.Append(whitespace[i]);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Analysis/Engine/Impl/ProjectEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ private void Parse(bool enqueueOnly, CancellationToken cancel) {
MyScope.Scope.ClearNodeValues();
MyScope.Scope.ClearLinkedVariables();
MyScope.Scope.ClearVariables();
MyScope.ClearReferencedModules();
MyScope.ClearUnresolvedModules();
_unit.State.ClearDiagnostics(this);

Expand Down Expand Up @@ -366,10 +367,7 @@ public void Dispose() {
}
}

foreach (var moduleReference in MyScope.ModuleReferences.ToList()) {
MyScope.RemoveModuleReference(moduleReference);
}

MyScope.ClearReferencedModules();
NewParseTree -= NewParseTree;
NewAnalysis -= NewAnalysis;
}
Expand Down
Loading