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

No diagnostic message when Generic is called with no args #1305

Merged
merged 2 commits into from
Jul 10, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ private IReadOnlyList<IMember> EvaluateIndex(IndexExpression expr) {
}
} else {
var index = GetValueFromExpression(expr.Index);
indices.Add(index ?? UnknownType);
// Don't count null indexes as arguments
if (index != null) {
indices.Add(index);
}
}
return indices;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Analysis/Ast/Impl/Analyzer/Evaluation/ExpressionEval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public IMember GetValueFromExpression(Expression expr, LookupOptions options = L
case NamedExpression namedExpr:
m = GetValueFromExpression(namedExpr.Value);
break;
// indexing with nothing, e.g Generic[]
case ErrorExpression error:
m = null;
break;
default:
m = GetValueFromBinaryOp(expr) ?? GetConstantFromLiteral(expr, options);
break;
Expand Down
21 changes: 20 additions & 1 deletion src/Analysis/Ast/Test/LintGenericTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,26 @@ public async Task GenericDuplicateArguments(string decl) {
public async Task GenericArgumentsNoDiagnosticOnValid(string decl) {
string code = GenericSetup + decl;
var analysis = await GetAnalysisAsync(code);
analysis.Diagnostics.Should().HaveCount(0);
analysis.Diagnostics.Should().BeEmpty();
}

[TestMethod, Priority(0)]
public async Task GenericNoArgumentsNoDiagnostic() {
string code = GenericSetup + @"
x = Generic[]
";
var analysis = await GetAnalysisAsync(code);
analysis.Diagnostics.Should().BeEmpty();
}


[TestMethod, Priority(0)]
public async Task GenericArgumentSpaceNoDiagnostic() {
string code = GenericSetup + @"
x = Generic[ ]
";
var analysis = await GetAnalysisAsync(code);
analysis.Diagnostics.Should().BeEmpty();
}
}
}