diff --git a/src/Compilers/CSharp/Portable/Binder/Binder.cs b/src/Compilers/CSharp/Portable/Binder/Binder.cs index 6279f1f7b0ba51278c4183a4b3ef9203e63baeb6..a789e1d97324436e7c29a869044aa1e53008b6e3 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder.cs @@ -778,7 +778,8 @@ internal Binder WithPatternVariablesIfAny(ArgumentListSyntax initializerArgument CSharpSyntaxNode node = null, ImmutableArray nodes = default(ImmutableArray)) { - var patterns = PatternVariableFinder.FindPatternVariables(node, nodes); + var patterns = ArrayBuilder.GetInstance(); + PatternVariableFinder.FindPatternVariables(patterns, node, nodes); foreach (var pattern in patterns) { builder.Add(SourceLocalSymbol.MakeLocal(ContainingMemberOrLambda, this, RefKind.None, pattern.Type, pattern.Identifier, LocalDeclarationKind.PatternVariable)); diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs index ecaae1e9dc55574ddcbba05ee029b1b2bf2c9d39..d3fbbb189f8608491b832020545f65bb15caef68 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs @@ -796,9 +796,9 @@ private TypeSymbol BindVariableType(CSharpSyntaxNode declarationNode, Diagnostic // Step out of the PatternVariableBinder for locals declared in variable declaration statement if (this is PatternVariableBinder) { - CSharpSyntaxNode parent; - if ((parent = declarator.Parent)?.Kind() == SyntaxKind.VariableDeclaration && - parent.Parent?.Kind() == SyntaxKind.LocalDeclarationStatement) + CSharpSyntaxNode parent = declarator.Parent; + if (parent?.Kind() == SyntaxKind.VariableDeclaration && + parent.Parent?.Kind() == SyntaxKind.LocalDeclarationStatement) { nameConflictChecker = this.Next; } diff --git a/src/Compilers/CSharp/Portable/Binder/PatternVariableFinder.cs b/src/Compilers/CSharp/Portable/Binder/PatternVariableFinder.cs index 9f163f7df0a94e00206a70851deb49e9e8f38cec..62ec014663587d2b0d47c7f824837cfdff5eb6ad 100644 --- a/src/Compilers/CSharp/Portable/Binder/PatternVariableFinder.cs +++ b/src/Compilers/CSharp/Portable/Binder/PatternVariableFinder.cs @@ -13,12 +13,14 @@ namespace Microsoft.CodeAnalysis.CSharp class PatternVariableFinder : CSharpSyntaxWalker { ArrayBuilder declarationPatterns; - internal static ArrayBuilder FindPatternVariables( + + internal static void FindPatternVariables( + ArrayBuilder builder, CSharpSyntaxNode node = null, ImmutableArray nodes = default(ImmutableArray)) { var finder = s_poolInstance.Allocate(); - finder.declarationPatterns = ArrayBuilder.GetInstance(); + finder.declarationPatterns = builder; finder.Visit(node); if (!nodes.IsDefaultOrEmpty) { @@ -28,10 +30,8 @@ class PatternVariableFinder : CSharpSyntaxWalker } } - var result = finder.declarationPatterns; finder.declarationPatterns = null; s_poolInstance.Free(finder); - return result; } public override void VisitDeclarationPattern(DeclarationPatternSyntax node)