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

Addrange on immutableArray creates a new ImmutableArray #69331

Merged
merged 1 commit into from
Aug 3, 2023
Merged
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 @@ -113,7 +113,7 @@ public async Task<FirstFixResult> GetMostSevereFixAsync(
}

var buildOnlyDiagnosticsService = document.Project.Solution.Services.GetRequiredService<IBuildOnlyDiagnosticsService>();
allDiagnostics.AddRange(buildOnlyDiagnosticsService.GetBuildOnlyDiagnostics(document.Id));
allDiagnostics = allDiagnostics.AddRange(buildOnlyDiagnosticsService.GetBuildOnlyDiagnostics(document.Id));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a unit test or an integration test for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mavasani @sharwell @jaredpar Is there an analyzer somewhere to generally catch mistakes like this? I know I've heard plenty of discussions of it, but did anybody ever write one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonmalinowski dotnet/runtime#34098 tracks adding such an analyzer driven by a new attribute in the framework. This is supposed to be lot more refined than all our existing analyzers in same space (IDE0058, IDE0059, etc.).
Tagging @eerhardt @buyaa-n as the primary champions for the design of that analyzer. Not sure if this will make it into .NET8 as it seems to have large cost estimate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we did have CA1806 which used to fire for the Collections.Immutable methods, but the [Pure] attribute was removed on these APIs in dotnet/runtime#35118. The CA1806 analyzer no longer fires because there are no [Pure] attributes on the APIs.

Not sure if this will make it into .NET8 as it seems to have large cost estimate.

No, dotnet/runtime#34098 has been pushed out of .NET 8.

cc @jeffhandley

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the interim, it might make sense to modify CA1806 to explicitly include items we know have return values that shouldn't be dropped.


var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
var spanToDiagnostics = ConvertToMap(text, allDiagnostics);
Expand Down