Skip to content

CSharpAddParameterCodeFixProvider does not work with top-level statements #44271

@AlekseyTs

Description

@AlekseyTs

Start with top-level statements:

local2(1, 2);

void local2(int x, int y)
{
}

Add a string literal as the 3rd argument at the call site of local2. Try to use "Add parameter" fix

Observed:

System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values.
Parameter name: index
   at Roslyn.Utilities.SpecializedCollections.Empty.List`1.get_Item(Int32 index)
   at async Microsoft.CodeAnalysis.AddParameter.AddParameterService.AddParameterAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.AddParameter.AbstractAddParameterCodeFixProvider`6.FixAsync[TArgumentSyntax,TAttributeArgumentSyntax,TArgumentListSyntax,TAttributeArgumentListSyntax,TInvocationExpressionSyntax,TObjectCreationExpressionSyntax](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass11_0.<GetPreviewAsync>b__0(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

Relates to #43563 (test plan for "top-level statements")

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions