Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not flag RS0012 for ToImmutable invocations if the contents of the… #1450

Merged
merged 4 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using Analyzer.Utilities;
using Analyzer.Utilities.Extensions;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -67,6 +68,16 @@ public override void Initialize(AnalysisContext context)
}

Debug.Assert(!string.IsNullOrEmpty(metadataName));

// Do not flag invocations that take any explicit argument (comparer, converter, etc.)
// as they can potentially modify the contents of the resulting collection.
// See https://github.com/dotnet/roslyn/issues/23625 for language specific implementation below.
var argumentsToSkip = targetMethod.IsExtensionMethod && invocation.Language != LanguageNames.VisualBasic ? 1 : 0;
if (invocation.Arguments.Skip(argumentsToSkip).Any(arg => arg.ArgumentKind == ArgumentKind.Explicit))
{
return;
}

var immutableCollectionType = compilation.GetTypeByMetadataName(metadataName);
if (immutableCollectionType == null)
{
Expand Down
Loading