Skip to content

Commit

Permalink
Don't suppress LHS diagnostics on augmented assign
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Arkhipov committed Nov 12, 2019
1 parent 0b28fa4 commit 6109ac7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public override bool Walk(SuiteStatement node) {
HandleNonLocal(nls);
break;
case AugmentedAssignStatement augs:
_suppressDiagnostics = true;
augs.Left?.Walk(new ExpressionWalker(this));
_suppressDiagnostics = false;
augs.Right?.Walk(new ExpressionWalker(this));
break;
case AssignmentStatement asst:
Expand Down
9 changes: 9 additions & 0 deletions src/Analysis/Ast/Test/AssignmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ def __init__(self):
.Which.Should().HaveMembers("abc", "y", "__class__");
}

[TestMethod, Priority(0)]
public async Task AugmentedAssignToUndefined() {
const string code = @"
x += 1
";
var analysis = await GetAnalysisAsync(code);
analysis.Should().NotHaveVariable("x");
}

[TestMethod, Priority(0)]
public async Task BaseInstanceVariable() {
const string code = @"
Expand Down
12 changes: 12 additions & 0 deletions src/Analysis/Ast/Test/LintUndefinedVarsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,18 @@ class Subclass(MyClass):
d.Should().BeEmpty();
}

[TestMethod, Priority(0)]
public async Task AugmentedAssignToUndefined() {
const string code = @"
x += 1
";
var d = await LintAsync(code);
d.Should().HaveCount(1);
d[0].ErrorCode.Should().Be(ErrorCodes.UndefinedVariable);
d[0].SourceSpan.Should().Be(2, 1, 2, 2);
}


private async Task<IReadOnlyList<DiagnosticsEntry>> LintAsync(string code, InterpreterConfiguration configuration = null) {
var analysis = await GetAnalysisAsync(code, configuration ?? PythonVersions.LatestAvailable3X);
var a = Services.GetService<IPythonAnalyzer>();
Expand Down

0 comments on commit 6109ac7

Please sign in to comment.