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

VB.NET: using framework type name as field name in value tuple crashes 'Extract Method' and 'Introduce Variable' refatorings #21662

Open
zaytsev-victor opened this issue Aug 22, 2017 · 11 comments
Assignees
Labels
Area-Compilers Bug Developer Community The issue was originally reported on https://developercommunity.visualstudio.com Feature - Extract Method
Milestone

Comments

@zaytsev-victor
Copy link
Contributor

Version Used:
VS 2017 15.3
Steps to Reproduce:

Dim product = (id:=1, [DateTime]:=DateTime.Now.ToString())
  1. Select DateTime.Now.ToString()
  2. Click in light bulb

Expected Behavior:
No errors
Actual Behavior:
'Extract Method' and 'Introduce Variable' refatorings crashes

'Extract Method' stack trace:

System.InvalidCastException : Unable to cast object of type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.MemberAccessExpressionSyntax' to type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.IdentifierNameSyntax'.
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitNameColonEquals(NameColonEqualsSyntax node)
   at Microsoft.CodeAnalysis.VisualBasic.Syntax.NameColonEqualsSyntax.Accept[TResult](VisualBasicSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplificationService.Expander.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitSimpleArgument(SimpleArgumentSyntax node)
   at Microsoft.CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplificationService.Expander.VisitSimpleArgument(SimpleArgumentSyntax node)
   at Microsoft.CodeAnalysis.VisualBasic.Syntax.SimpleArgumentSyntax.Accept[TResult](VisualBasicSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplificationService.Expander.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitListElement[TNode](TNode node)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitList[TNode](SeparatedSyntaxList`1 list)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitTupleExpression(TupleExpressionSyntax node)
   at Microsoft.CodeAnalysis.VisualBasic.Syntax.TupleExpressionSyntax.Accept[TResult](VisualBasicSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplificationService.Expander.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplificationService.Expand(SyntaxNode node,SemanticModel semanticModel,SyntaxAnnotation aliasReplacementAnnotation,Func`2 expandInsideNode,Boolean expandParameter,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Simplification.Simplifier.Expand[TNode](TNode node,SemanticModel semanticModel,Workspace workspace,Func`2 expandInsideNode,Boolean expandParameter,CancellationToken cancellationToken)
   at async Microsoft.CodeAnalysis.Simplification.Simplifier.ExpandAsync[TNode](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.VisualBasic.ExtractMethod.VisualBasicMethodExtractor.VB$StateMachine_7_ExpandAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.ExtractMethod.MethodExtractor.ExtractMethodAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.ExtractMethod.AbstractExtractMethodService`3.ExtractMethodAsync[TValidator,TExtractor,TResult](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.ExtractMethod.ExtractMethodCodeRefactoringProvider.GetCodeActionAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.ExtractMethod.ExtractMethodCodeRefactoringProvider.ComputeRefactoringsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

'Introduce Variable' stack trace:

System.InvalidCastException : Unable to cast object of type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.MemberAccessExpressionSyntax' to type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.IdentifierNameSyntax'.
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitNameColonEquals(NameColonEqualsSyntax node)
   at Microsoft.CodeAnalysis.VisualBasic.Syntax.NameColonEqualsSyntax.Accept[TResult](VisualBasicSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplificationService.Expander.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitSimpleArgument(SimpleArgumentSyntax node)
   at Microsoft.CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplificationService.Expander.VisitSimpleArgument(SimpleArgumentSyntax node)
   at Microsoft.CodeAnalysis.VisualBasic.Syntax.SimpleArgumentSyntax.Accept[TResult](VisualBasicSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplificationService.Expander.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitListElement[TNode](TNode node)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitList[TNode](SeparatedSyntaxList`1 list)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.VisitTupleExpression(TupleExpressionSyntax node)
   at Microsoft.CodeAnalysis.VisualBasic.Syntax.TupleExpressionSyntax.Accept[TResult](VisualBasicSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxRewriter.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplificationService.Expander.Visit(SyntaxNode node)
   at Microsoft.CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplificationService.Expand(SyntaxNode node,SemanticModel semanticModel,SyntaxAnnotation aliasReplacementAnnotation,Func`2 expandInsideNode,Boolean expandParameter,CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Simplification.Simplifier.Expand[TNode](TNode node,SemanticModel semanticModel,Workspace workspace,Func`2 expandInsideNode,Boolean expandParameter,CancellationToken cancellationToken)
   at async Microsoft.CodeAnalysis.Simplification.Simplifier.ExpandAsync[TNode](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.IntroduceVariable.AbstractIntroduceVariableService`5.<>c__DisplayClass34_0.<ComplexifyParentingStatements>b__1[TService,TExpressionSyntax,TTypeSyntax,TTypeDeclarationSyntax,TQueryExpressionSyntax](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Shared.Extensions.SyntaxNodeExtensions.ReplaceSyntaxAsync[TRoot](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.IntroduceVariable.AbstractIntroduceVariableService`5.ComplexifyParentingStatements[TService,TExpressionSyntax,TTypeSyntax,TTypeDeclarationSyntax,TQueryExpressionSyntax](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.VisualBasic.IntroduceVariable.VisualBasicIntroduceVariableService.VB$StateMachine_28_IntroduceLocalDeclarationIntoBlockAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.VisualBasic.IntroduceVariable.VisualBasicIntroduceVariableService.VB$StateMachine_24_IntroduceLocalAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.IntroduceVariable.AbstractIntroduceVariableService`5.AbstractIntroduceVariableCodeAction.GetChangedDocumentCoreAsync[TService,TExpressionSyntax,TTypeSyntax,TTypeDeclarationSyntax,TQueryExpressionSyntax](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.IntroduceVariable.AbstractIntroduceVariableService`5.AbstractIntroduceVariableCodeAction.GetChangedDocumentAsync[TService,TExpressionSyntax,TTypeSyntax,TTypeDeclarationSyntax,TQueryExpressionSyntax](<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.ComputePreviewOperationsAsync(<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)
@Pilchie Pilchie added this to the 15.5 milestone Aug 23, 2017
@jinujoseph jinujoseph modified the milestones: 15.5, 15.7 Oct 14, 2017
@jinujoseph jinujoseph modified the milestones: 15.7, Unknown Nov 1, 2017
@jinujoseph jinujoseph added the Developer Community The issue was originally reported on https://developercommunity.visualstudio.com label Apr 10, 2019
@jinujoseph jinujoseph added this to Backlog in IDE: InternalPriority via automation Apr 10, 2019
@jinujoseph
Copy link
Contributor

jinujoseph commented Apr 10, 2019

Also reported at DC

Also reported at DC

@jinujoseph jinujoseph moved this from Backlog to P1-Bugs in IDE: InternalPriority Apr 10, 2019
@jinujoseph jinujoseph assigned ryzngard and unassigned sharwell Apr 10, 2019
@jinujoseph jinujoseph modified the milestones: Backlog, 16.1.P3 Apr 10, 2019
@jinujoseph jinujoseph moved this from P1-Bugs to Planned in IDE: InternalPriority Apr 23, 2019
@ryzngard
Copy link
Contributor

@AlekseyTs can you take a look at this? It looks like the [DateTime] escaped named parameter for the tuple is being treated as a namedtype by the semantic model.

This commit has a test I concocted that shows the symbol information being the namedtype System.DateTime when it shouldn't be. It also has the IDE test I used to narrow down before I made the compiler test.

@AlekseyTs
Copy link
Contributor

CC @jcouv

@jcouv
Copy link
Member

jcouv commented Apr 24, 2019

a test I concocted that shows the symbol information being the namedtype System.DateTime when it shouldn't be.

I didn't quite follow. The test has: Assert.Null(dateTimeNameInfo.Symbol). Does the test in this commit fail? If yes, then let's move to the compiler area.

@ryzngard
Copy link
Contributor

Yes, the test fails

    Message: Assert.Null() Failure
      Expected: (null)
      Actual:   Date

@jinujoseph jinujoseph modified the milestones: 16.1.P3, 16.1 Apr 24, 2019
@ryzngard
Copy link
Contributor

@jcouv moving to Area-Compilers

@jcouv jcouv assigned jcouv and unassigned ryzngard Apr 25, 2019
@jcouv jcouv modified the milestones: 16.1, 16.2 Apr 25, 2019
@AdamSpeight2008
Copy link
Contributor

@jcouv This is related to #29233.
Approach is this, if the identifier is followed by a member qualifier . ? ! and is a keyword that is unescaped. Mark it an error, but continue as if was a valid identifier. This allows the rest of the expression / statement to be parsed relatively correctly. As well the option to have code fix to escape the keyword. I've tried this in a fork of mine, has few test failures related to classification though
The semantic analysis then has to validate if the "identifier" is a valid member lookup on the type, ie is a shared method. I've not done this part.

@jcouv jcouv modified the milestones: 16.2, 16.3, Compiler.Next Jun 25, 2019
@amelvill
Copy link

hi @jinujoseph , how is this issue related to the one I reported on DC? https://developercommunity.visualstudio.com/content/problem/506257/hard-crash-to-desktop-when-renaming-a-variable-in.html#

It seems like this issue has to do with keyword escaping where the problem I ran into has to do with using the field of any class as an iteration variable.

@jinujoseph
Copy link
Contributor

@ryzngard to investigate the DC issue.

@ryzngard
Copy link
Contributor

ryzngard commented Aug 5, 2019

@amelvill while the repro steps and scenario may be different, the underlying issue for both are closely tied and will be resolved by the same fix based on our investigation. This line appears to be the culprit of the DC issue. #29233 also seems to be related, as noted by Adam above. As part of the fix, all scenarios linked to the issue should be tested to verify they are also resolved.

@amelvill
Copy link

amelvill commented Aug 5, 2019

@ryzngard Understood, thanks for the update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Developer Community The issue was originally reported on https://developercommunity.visualstudio.com Feature - Extract Method
Projects
Development

No branches or pull requests