Skip to content

VB Quick Action, Generate Equal(Object) crashes #45919

@paul1956

Description

@paul1956

🔗 Also tracked as AB#1268360

Version Used:

Steps to Reproduce:

  1. Create Class
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.

<Reflection.DefaultMember("Value")>
Public Class IntegerRange
    Private ReadOnly _anyOf() As Integer
    Private _range? As (Start As Integer, [End] As Integer)
    Private _value As Integer

    Public Sub New(value As Integer, anyOf() As Integer)
        _anyOf = anyOf
        Me.Set(value)
    End Sub

    Public Sub New(value As Integer, range As (Start As Integer, [End] As Integer))
        _range = range
        Me.Set(value)
    End Sub

    Public Sub New(range As (Start As Integer, [End] As Integer), anyOf() As Integer)
        _range = range
        _anyOf = anyOf
        Me.Set(_value)
    End Sub

    Public Sub New(anyOf() As Integer)
        _anyOf = anyOf
    End Sub

    Public Sub New(start As Integer, [end] As Integer)
        _range = (start, [end])
    End Sub

    Public Sub New(start As Integer, [end] As Integer, anyOf() As Integer)
        _range = (start, [end])
        _anyOf = anyOf
    End Sub

    Public ReadOnly Property Value As Integer
        Get
            Return _value
        End Get
    End Property

    Public Sub [Set](n As Integer)
        If _anyOf?.Contains(n) Then
            _value = n
            Return
        End If

        If _range.HasValue AndAlso n >= _range.Value.Start AndAlso n <= _range.Value.End Then
            _value = n
            Return
        End If

        Throw New ArgumentOutOfRangeException(NameOf(n))
    End Sub

End Class
  1. Right Click on class name and select Quick Action, Generate Equal(Object)
  2. Select Value uncheck the rest (may not be neccessary), then OK, you get a crash
    4 Enable and repeat but select nothing on first list but check either or both of the bottom check boxes the OK, you get a crash

Expected Behavior:
All the items get generated

Actual Behavior:
CheckDeclarationNode expects a block but it is called with a ClassStatement.

System.ArgumentException : Destination type must be a TypeBlockSyntax, CompilationUnitSyntax or NamespaceBlockSyntax, but given one is ClassStatementSyntax.
Parameter name: destination
   at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.CheckDeclarationNode[TDeclarationNode1,TDeclarationNode2,TDeclarationNode3](SyntaxNode destination)
   at Microsoft.CodeAnalysis.VisualBasic.CodeGeneration.VisualBasicCodeGenerationService.AddMethod[TDeclarationNode](TDeclarationNode destination,IMethodSymbol method,CodeGenerationOptions options,IList`1 availableIndices)
   at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.UpdateDestination[TDeclarationNode](IList`1 availableIndices,CodeGenerationOptions options,TDeclarationNode currentDestination,ISymbol member,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembersToAppropiateLocationInDestination[TDeclarationSyntax](TDeclarationSyntax destination,IEnumerable`1 members,IList`1 availableIndices,CodeGenerationOptions options,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembers[TDeclarationNode](TDeclarationNode destination,IEnumerable`1 members,IList`1 availableIndices,CodeGenerationOptions options,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CodeGeneration.AbstractCodeGenerationService.AddMembers[TDeclarationNode](TDeclarationNode destination,IEnumerable`1 members,CodeGenerationOptions options,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CodeGeneration.CodeGenerator.AddMemberDeclarations[TDeclarationNode](TDeclarationNode destination,IEnumerable`1 members,Workspace workspace,CodeGenerationOptions options)
   at async Microsoft.CodeAnalysis.GenerateEqualsAndGetHashCodeFromMembers.GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.GenerateEqualsAndGetHashCodeAction.GetChangedDocumentAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetOperationsCoreAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.GenerateEqualsAndGetHashCodeFromMembers.GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.GenerateEqualsAndGetHashCodeWithDialogCodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeActionWithOptions.GetOperationsAsync(<Unknown Parameters>)
   at Roslyn.Utilities.TaskExtensions.WaitAndGetResult_CanCallOnBackground[T](Task`1 task,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.InvokeWorker(Func`1 getFromDocument,IProgressTracker progressTracker,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.<>c__DisplayClass20_0.<InvokeCore>b__0()
   at Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformAction(IExtensionManager extensionManager,Object extension,Action action)
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

Metadata

Metadata

Assignees

No one assigned

    Labels

    4 - In ReviewA fix for the issue is submitted for review.Area-IDEBugDeveloper CommunityThe issue was originally reported on https://developercommunity.visualstudio.comIDE-CodeStyleBuilt-in analyzers, fixes, and refactorings

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions