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

Exception in ChangeSignatureCodeRefactoringProvider after wrong automatic closing brace placement #65298

Closed
jhinder opened this issue Nov 9, 2022 · 1 comment · Fixed by #65307
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@jhinder
Copy link
Contributor

jhinder commented Nov 9, 2022

Version Used: VS 2022 17.4.0

Steps to Reproduce:

  1. Place the cursor at the marked location
  2. Insert {.
  3. Press the Return key.

Note that the parentheses are balanced at the start.

namespace N;

internal class C
{
    private void M()
    {
        M1(x => M2("a", y => M3<int>(z => $$)));
    }

    private void M1(Action<object> a) { }

    private void M2(string a, Action<object> e) { }

    private void M3<T>(Action<T> a) { }
}

Expected Behavior:

  1. The closing brace is placed at the correct location, forming an empty statement block:
    M1(x => M2("a", y => M3<int>(z => { })));
  2. The refactoring does not crash due to the malformed syntax.

Actual Behavior:

  1. The closing brace is placed between the second and third closing parenthesis, leading to malformed syntax: M1(x => M2("a", y => M3<int>(z => {))});
  2. After pressing Return the ChangeSignatureCodeRefactoringProvider throws an exception, leading to a gold bar. The stack trace is posted below.

The second problem does not seem to occur when the namespace declaration is missing.

System.NullReferenceException : Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.ChangeSignature.AbstractChangeSignatureService.GetParameterIndexFromInvocationArgument(SyntaxNode argument,Document document,SemanticModel semanticModel,CancellationToken cancellationToken)
   at async Microsoft.CodeAnalysis.CSharp.ChangeSignature.CSharpChangeSignatureService.GetInvocationSymbolAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.ChangeSignature.AbstractChangeSignatureService.GetChangeSignatureContextAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.ChangeSignature.AbstractChangeSignatureService.GetChangeSignatureCodeActionAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.ChangeSignature.ChangeSignatureCodeRefactoringProvider.ComputeRefactoringsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 9, 2022
@jhinder
Copy link
Contributor Author

jhinder commented Nov 9, 2022

The faulty closing brace placement appears to be fixed in VS 17.5 Preview 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant