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

Conversation

gero3
Copy link
Contributor

@gero3 gero3 commented Aug 2, 2023

The buildonlydiagnostics don't get evaluated because of this.

The buildonlydiagnostics don't get evaluated because of this.
@gero3 gero3 requested a review from a team as a code owner August 2, 2023 11:33
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 2, 2023
@ghost ghost added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Aug 2, 2023
@@ -113,7 +113,7 @@ internal partial class CodeFixService : ICodeFixService
}

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.

@mavasani
Copy link
Contributor

mavasani commented Aug 2, 2023

The fix looks good to me, but this shouldn’t impact the code fix path for light bulb invocation as we already do the right thing for that:

diagnostics = diagnostics.AddRange(buildOnlyDiagnostics);

This fix will resolve the issue that if a line only has a fixable build-only diagnostic and no other code fix or refactoring on the same line, you would have not seen the light bulb in the margin from background analysis. I don’t believe that part can be tested thought, so I am good to sign off on this change without adding a test

@@ -113,7 +113,7 @@ internal partial class CodeFixService : ICodeFixService
}

var buildOnlyDiagnosticsService = document.Project.Solution.Services.GetRequiredService<IBuildOnlyDiagnosticsService>();
allDiagnostics.AddRange(buildOnlyDiagnosticsService.GetBuildOnlyDiagnostics(document.Id));
allDiagnostics = allDiagnostics.AddRange(buildOnlyDiagnosticsService.GetBuildOnlyDiagnostics(document.Id));
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.

@mavasani mavasani merged commit 66f37d3 into dotnet:main Aug 3, 2023
24 checks passed
@ghost ghost added this to the Next milestone Aug 3, 2023
@dibarbet dibarbet modified the milestones: Next, 17.8 P2 Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants