Skip to content
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 @@ -170,5 +170,78 @@ public unsafe void TestMethod()

await VerifyCSharpDiagnosticAsync(LanguageVersion.CSharp8, testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3370, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3370")]
public async Task TestRangeFollowedByMemberCallAsync()
{
const string testCode = @"using System;

public class TestClass
{
public void TestMethod()
{
var array = (1..10).ToString();
}
}
";

await new CSharpTest(LanguageVersion.CSharp8)
{
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp31,
TestCode = testCode,
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3370, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3370")]
public async Task TestRangeAsync()
{
const string testCode = @"using System;

public class TestClass
{
public void TestMethod()
{
var a = new int[0];
var b = a[(..)];
var range = (1..10);
}
}
";

const string fixedCode = @"using System;

public class TestClass
{
public void TestMethod()
{
var a = new int[0];
var b = a[..];
var range = 1..10;
}
}
";

DiagnosticResult[] expected =
{
Diagnostic(DiagnosticId).WithSpan(8, 19, 8, 23),
Diagnostic(ParenthesesDiagnosticId).WithLocation(8, 19),
Diagnostic(ParenthesesDiagnosticId).WithLocation(8, 22),
Diagnostic(DiagnosticId).WithSpan(9, 21, 9, 28),
Diagnostic(ParenthesesDiagnosticId).WithLocation(9, 21),
Diagnostic(ParenthesesDiagnosticId).WithLocation(9, 27),
};

var test = new CSharpTest(LanguageVersion.CSharp8)
{
ReferenceAssemblies = ReferenceAssemblies.NetCore.NetCoreApp31,
TestCode = testCode,
FixedCode = fixedCode,
};
test.ExpectedDiagnostics.AddRange(expected);

await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private static void HandleParenthesizedExpression(SyntaxNodeAnalysisContext cont
&& !node.Expression.IsKind(SyntaxKind.CoalesceExpression)
&& !node.Expression.IsKind(SyntaxKind.QueryExpression)
&& !node.Expression.IsKind(SyntaxKind.AwaitExpression)
&& !node.Expression.IsKind(SyntaxKindEx.RangeExpression)
&& !node.IsKind(SyntaxKind.ConstructorDeclaration))
{
if (node.Expression.IsKind(SyntaxKind.ConditionalAccessExpression)
Expand Down