Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
update
  • Loading branch information
josefpihrt committed Sep 27, 2024
commit 7791fc24b5a8df6abaa8617f1f952716358d7b7e
2 changes: 1 addition & 1 deletion src/Common/CSharp/Analysis/UseElementAccessAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static bool IsFixableLast(
if (((CSharpCompilation)semanticModel.Compilation).LanguageVersion < LanguageVersion.CSharp8)
return false;

if (semanticModel.Compilation.GetTypeByMetadataName("System.Index") is null)
if (semanticModel.Compilation.GetTypeByMetadataName("System.Index")?.DeclaredAccessibility != Accessibility.Public)
return false;

IMethodSymbol methodSymbol = semanticModel.GetReducedExtensionMethodInfo(invocationInfo.InvocationExpression, cancellationToken).Symbol;
Expand Down
17 changes: 17 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1246UseElementAccessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,23 @@ void M()
", source, expected);
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseElementAccess)]
public async Task Test_UseElementAccessInsteadOfLast_CSharp7()
{
await VerifyNoDiagnosticAsync(@"
using System.Collections.Generic;

class C
{
void M()
{
List<string> x = null;
var y = x.Last();
}
}
", options: WellKnownCSharpTestOptions.Default_CSharp7);
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseElementAccess)]
public async Task TestNoDiagnostic_UseElementAccessInsteadOfLast()
{
Expand Down