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 CSharpAddParameterCheckCodeRefactoringProvider when changing type of indexer argument #63307

Closed
jhinder opened this issue Aug 10, 2022 · 0 comments · Fixed by #63351
Labels
Area-IDE help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@jhinder
Copy link
Contributor

jhinder commented Aug 10, 2022

Version Used: VS 17.3, Roslyn 4.3.0-3.22401.3

Steps to Reproduce:

  1. Take the code below.
  2. Select the type of the indexer argument and type any type name (valid or invalid).
  3. A gold bar appears, stating "'CSharpAddParameterCheckCodeRefactoringProvider' encountered an error and has been disabled."
record R
{
    public int this[int i]
    {
        get => default;
    }
}

Stack trace:

System.InvalidCastException : Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.PropertySymbol' to type 'Microsoft.CodeAnalysis.IMethodSymbol'.
   at async Microsoft.CodeAnalysis.InitializeParameter.AbstractInitializeParameterCodeRefactoringProvider`4.ComputeRefactoringsAsync[TTypeDeclarationSyntax,TParameterSyntax,TStatementSyntax,TExpressionSyntax](<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)

Notes:

  • Seems to affect only record types, not class or struct.
  • An accessor must be explicitly defined (i.e. this[X x] => 0 is not affected), and it can be any of get, set or init.

Expected Behavior: No exception.

Actual Behavior: Exception and gold bar.

@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 10, 2022
@dibarbet dibarbet added help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 15, 2022
@dibarbet dibarbet added this to the Backlog milestone Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants