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

Inline Declaration refactoring on out parameter crashes IDE #16306

Closed
CyrusNajmabadi opened this issue Jan 6, 2017 · 7 comments
Closed

Inline Declaration refactoring on out parameter crashes IDE #16306

CyrusNajmabadi opened this issue Jan 6, 2017 · 7 comments

Comments

@CyrusNajmabadi
Copy link
Member

Start with the following code:

using System;
using System.Collections.Generic;

class C
{
    void Foo()
    {
        int rowCountMember;
        var item = "";
        int rowCount;
        foreach (var row in function1(item, out rowCount))
        {
            function2(row);
        }

        rowCountMember = rowCount;
    }

    private IEnumerable<object> function1(string item, out int rowCount)
    {
        throw new NotImplementedException();
    }

    private void function2(object row)
    {
        throw new NotImplementedException();
    }
}

Try to invoke 'inline declaration' on int rowCount. This crashes the IDE with this callstack:

>	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.MemberSemanticModel.GetForEachStatementInfo(Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax node) Line 776	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.SyntaxTreeSemanticModel.GetForEachStatementInfo(Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax node) Line 2117	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetForEachStatementInfo(Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax forEachStatement) Line 720	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Utilities.SpeculationAnalyzer.GetForEachSymbols(Microsoft.CodeAnalysis.SemanticModel model, Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax forEach, out Microsoft.CodeAnalysis.IMethodSymbol getEnumeratorMethod, out Microsoft.CodeAnalysis.ITypeSymbol elementType) Line 714	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Shared.Utilities.AbstractSpeculationAnalyzer<Microsoft.CodeAnalysis.SyntaxNode, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.ThrowStatementSyntax, Microsoft.CodeAnalysis.SemanticModel, Microsoft.CodeAnalysis.CSharp.Conversion>.ReplacementBreaksForEachStatement(Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax forEachStatement, Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax newForEachStatement) Line 566	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Shared.Utilities.AbstractSpeculationAnalyzer<Microsoft.CodeAnalysis.SyntaxNode, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.ThrowStatementSyntax, Microsoft.CodeAnalysis.SemanticModel, Microsoft.CodeAnalysis.CSharp.Conversion>.ReplacementChangesSemanticsForNode(Microsoft.CodeAnalysis.SyntaxNode currentOriginalNode, Microsoft.CodeAnalysis.SyntaxNode currentReplacedNode, Microsoft.CodeAnalysis.SyntaxNode previousOriginalNode, Microsoft.CodeAnalysis.SyntaxNode previousReplacedNode) Line 496	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Shared.Utilities.AbstractSpeculationAnalyzer<Microsoft.CodeAnalysis.SyntaxNode, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.ThrowStatementSyntax, Microsoft.CodeAnalysis.SemanticModel, Microsoft.CodeAnalysis.CSharp.Conversion>.ReplacementChangesSemantics(Microsoft.CodeAnalysis.SyntaxNode currentOriginalNode, Microsoft.CodeAnalysis.SyntaxNode currentReplacedNode, Microsoft.CodeAnalysis.SyntaxNode originalRoot, bool skipVerificationForCurrentNode) Line 437	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Shared.Utilities.AbstractSpeculationAnalyzer<Microsoft.CodeAnalysis.SyntaxNode, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.CommonForEachStatementSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.ThrowStatementSyntax, Microsoft.CodeAnalysis.SemanticModel, Microsoft.CodeAnalysis.CSharp.Conversion>.ReplacementChangesSemantics() Line 416	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Extensions.ExpressionSyntaxExtensions.CanReplaceWithReducedName(Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax name, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax reducedName, Microsoft.CodeAnalysis.SemanticModel semanticModel, System.Threading.CancellationToken cancellationToken) Line 1955	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Extensions.ExpressionSyntaxExtensions.TryReduce(Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax name, Microsoft.CodeAnalysis.SemanticModel semanticModel, out Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax replacementNode, out Microsoft.CodeAnalysis.Text.TextSpan issueSpan, Microsoft.CodeAnalysis.Options.OptionSet optionSet, System.Threading.CancellationToken cancellationToken) Line 1477	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Extensions.ExpressionSyntaxExtensions.TryReduceExplicitName(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression, Microsoft.CodeAnalysis.SemanticModel semanticModel, out Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax replacementNode, out Microsoft.CodeAnalysis.Text.TextSpan issueSpan, Microsoft.CodeAnalysis.Options.OptionSet optionSet, System.Threading.CancellationToken cancellationToken) Line 697	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Extensions.ExpressionSyntaxExtensions.TryReduceOrSimplifyExplicitName(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression, Microsoft.CodeAnalysis.SemanticModel semanticModel, out Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax replacementNode, out Microsoft.CodeAnalysis.Text.TextSpan issueSpan, Microsoft.CodeAnalysis.Options.OptionSet optionSet, System.Threading.CancellationToken cancellationToken) Line 664	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Simplification.CSharpNameReducer.SimplifyName(Microsoft.CodeAnalysis.SyntaxNode node, Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.Options.OptionSet optionSet, System.Threading.CancellationToken cancellationToken) Line 42	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Simplification.AbstractCSharpReducer.AbstractExpressionRewriter.SimplifyNode<Microsoft.CodeAnalysis.CSharp.Syntax.AliasQualifiedNameSyntax>(Microsoft.CodeAnalysis.CSharp.Syntax.AliasQualifiedNameSyntax node, Microsoft.CodeAnalysis.SyntaxNode newNode, Microsoft.CodeAnalysis.SyntaxNode parentNode, System.Func<Microsoft.CodeAnalysis.CSharp.Syntax.AliasQualifiedNameSyntax, Microsoft.CodeAnalysis.SemanticModel, Microsoft.CodeAnalysis.Options.OptionSet, System.Threading.CancellationToken, Microsoft.CodeAnalysis.SyntaxNode> simplifier) Line 104	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Simplification.AbstractCSharpReducer.AbstractExpressionRewriter.SimplifyExpression<Microsoft.CodeAnalysis.CSharp.Syntax.AliasQualifiedNameSyntax>(Microsoft.CodeAnalysis.CSharp.Syntax.AliasQualifiedNameSyntax expression, Microsoft.CodeAnalysis.SyntaxNode newNode, System.Func<Microsoft.CodeAnalysis.CSharp.Syntax.AliasQualifiedNameSyntax, Microsoft.CodeAnalysis.SemanticModel, Microsoft.CodeAnalysis.Options.OptionSet, System.Threading.CancellationToken, Microsoft.CodeAnalysis.SyntaxNode> simplifier) Line 128	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Simplification.CSharpNameReducer.Rewriter.VisitAliasQualifiedName(Microsoft.CodeAnalysis.CSharp.Syntax.AliasQualifiedNameSyntax node) Line 48	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.AliasQualifiedNameSyntax.Accept<Microsoft.CodeAnalysis.SyntaxNode>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<Microsoft.CodeAnalysis.SyntaxNode> visitor) Line 423	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(Microsoft.CodeAnalysis.SyntaxNode node) Line 37	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitQualifiedName(Microsoft.CodeAnalysis.CSharp.Syntax.QualifiedNameSyntax node) Line 2481	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Simplification.CSharpNameReducer.Rewriter.VisitQualifiedName(Microsoft.CodeAnalysis.CSharp.Syntax.QualifiedNameSyntax node) Line 66	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.QualifiedNameSyntax.Accept<Microsoft.CodeAnalysis.SyntaxNode>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<Microsoft.CodeAnalysis.SyntaxNode> visitor) Line 150	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(Microsoft.CodeAnalysis.SyntaxNode node) Line 37	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitDeclarationExpression(Microsoft.CodeAnalysis.CSharp.Syntax.DeclarationExpressionSyntax node) Line 2801	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.DeclarationExpressionSyntax.Accept<Microsoft.CodeAnalysis.SyntaxNode>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<Microsoft.CodeAnalysis.SyntaxNode> visitor) Line 3836	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(Microsoft.CodeAnalysis.SyntaxNode node) Line 37	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitArgument(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax node) Line 2788	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax.Accept<Microsoft.CodeAnalysis.SyntaxNode>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<Microsoft.CodeAnalysis.SyntaxNode> visitor) Line 3672	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(Microsoft.CodeAnalysis.SyntaxNode node) Line 37	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitListElement<Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax>(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax node) Line 163	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitList<Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax>(Microsoft.CodeAnalysis.SeparatedSyntaxList<Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax> list) Line 216	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitArgumentList(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax node) Line 2771	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax.Accept<Microsoft.CodeAnalysis.SyntaxNode>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<Microsoft.CodeAnalysis.SyntaxNode> visitor) Line 3469	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(Microsoft.CodeAnalysis.SyntaxNode node) Line 37	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Simplification.AbstractCSharpReducer.AbstractExpressionRewriter.VisitInvocationExpression(Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax node) Line 161	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax.Accept<Microsoft.CodeAnalysis.SyntaxNode>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<Microsoft.CodeAnalysis.SyntaxNode> visitor) Line 3277	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(Microsoft.CodeAnalysis.SyntaxNode node) Line 37	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitForEachStatement(Microsoft.CodeAnalysis.CSharp.Syntax.ForEachStatementSyntax node) Line 3278	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.Syntax.ForEachStatementSyntax.Accept<Microsoft.CodeAnalysis.SyntaxNode>(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor<Microsoft.CodeAnalysis.SyntaxNode> visitor) Line 9391	C#
 	Microsoft.CodeAnalysis.CSharp.dll!Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.Visit(Microsoft.CodeAnalysis.SyntaxNode node) Line 37	C#
 	Microsoft.CodeAnalysis.CSharp.Workspaces.dll!Microsoft.CodeAnalysis.CSharp.Simplification.AbstractCSharpReducer.AbstractExpressionRewriter.VisitNodeOrToken(Microsoft.CodeAnalysis.SyntaxNodeOrToken nodeOrToken, Microsoft.CodeAnalysis.SemanticModel semanticModel, bool simplifyAllDescendants) Line 176	C#
 	Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Simplification.AbstractSimplificationService<Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.StatementSyntax, Microsoft.CodeAnalysis.CSharp.Syntax.CrefSyntax>.ReduceAsync.AnonymousMethod__0() Line 246	C#

With an exception:

System.InvalidCastException: 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.BoundBlock' to type 'Microsoft.CodeAnalysis.CSharp.BoundForEachStatement'.'
@CyrusNajmabadi
Copy link
Member Author

Tagging @gafter .

@Pilchie
Copy link
Member

Pilchie commented Jan 6, 2017

Did this come from a DeveloperCommunity issue for this? Can you link it here?

@gafter gafter added the Bug label Jan 8, 2017
@gafter gafter added this to the 2.0 (RC.3) milestone Jan 8, 2017
@jaredpar jaredpar modified the milestones: 2.0 (RTM), 2.0 (RC.3) Jan 8, 2017
@jcouv jcouv changed the title Inline declaration crashes IDE. Inline Declaration refactoring on out parameter crashes IDE Jan 16, 2017
@jcouv jcouv assigned jcouv and unassigned AlekseyTs Jan 18, 2017
@jcouv
Copy link
Member

jcouv commented Jan 19, 2017

@jcouv jcouv modified the milestones: 2.1, 2.0 (RTM) Jan 20, 2017
@jcouv jcouv added 4 - In Review A fix for the issue is submitted for review. and removed 3 - Working labels Jan 21, 2017
@jcouv jcouv added 3 - Working and removed 4 - In Review A fix for the issue is submitted for review. labels Feb 11, 2017
@jcouv jcouv modified the milestones: 2.1, 2.2 Mar 3, 2017
@gafter
Copy link
Member

gafter commented Mar 9, 2017

No longer tracked by VSO.

@gafter
Copy link
Member

gafter commented Mar 9, 2017

See also #10604

@CyrusNajmabadi
Copy link
Member Author

Please enable CSharpInlineDeclarationTests.TestInLoops3 when this is fixed.

@jcouv jcouv modified the milestones: 15.2, 15.3 Mar 11, 2017
@jcouv jcouv removed the 3 - Working label Apr 6, 2017
@jcouv
Copy link
Member

jcouv commented Apr 6, 2017

Load-balancing back to Aleksey. I didn't get time to investigate.

AlekseyTs added a commit to AlekseyTs/roslyn that referenced this issue Apr 13, 2017
… cache in order to avoid “polluting” regular cache.

Fixes dotnet#10604.
Fixes dotnet#16306.
AlekseyTs added a commit that referenced this issue Apr 15, 2017
… cache in order to avoid “polluting” regular cache. (#18662)

Fixes #10604.
Fixes #16306.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants