dotnet/roslyn

FixALl issue with 'remove redundant assignment' (IDE0059)

Offen

#53.960 geöffnet am 09.06.2021

 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)C# (4.257 Forks)batch import
Area-IDEBugFeature - IDE0059IDE-CodeStyleRetriagehelp wanted

Repository-Metriken

Stars
 (20.414 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)

Beschreibung

Happened while fixing up code in roslyn. original code is:

            ResultProperties resultProperties;
            string error;
            var testData = Evaluate(
                source,
                OutputKind.DynamicallyLinkedLibrary,
                methodName: "C.M",
                expr: "global::$exception",
                resultProperties: out resultProperties,
                error: out error);

both resultProperties and testData are unused. FixAll crashes with:

System.InvalidOperationException : GetCurrentNode returned null with the following node: resultProperties
   at Roslyn.Utilities.Contract.Fail(String message)
   at Microsoft.CodeAnalysis.Editing.SyntaxEditor.ReplaceChange.Apply(SyntaxNode root,SyntaxGenerator generator)
   at Microsoft.CodeAnalysis.Editing.SyntaxEditor.GetChangedRoot()
   at async Microsoft.CodeAnalysis.RemoveUnusedParametersAndValues.AbstractRemoveUnusedValuesCodeFixProvider`11.FixAllAsync[TExpressionSyntax,TStatementSyntax,TBlockSyntax,TExpressionStatementSyntax,TLocalDeclarationStatementSyntax,TVariableDeclaratorSyntax,TForEachStatementSyntax,TSwitchCaseBlockSyntax,TSwitchCaseLabelOrClauseSyntax,TCatchStatementSyntax,TCatchBlockSyntax](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.<GetFixAllProvider>b__2_0(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.<>c__DisplayClass8_1.<GetFixedDocumentsAsync>b__2(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.GetFixedDocumentsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.FixSingleContextAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.FixAllContextsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeFixes.DefaultFixAllProviderHelpers.GetFixAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.FixAllGetFixesService.GetFixAllCodeActionAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.FixAllGetFixesService.GetFixAllOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetOperationsCoreAsync(<Unknown Parameters>)

My psychic guess is that our fix all fails here when you have both an out parameter that is becoming a discard and the assignment is transformed to a discard as well. When trying to do both, we die.

Contributor Guide