/// <summary> /// Prepares locals corresponding to the variables of the declaration. /// The locals are kept in a tree which captures the nesting of variables. /// Each local is either a simple local (when its type is known) or a deconstruction local pending inference. /// The caller is responsible for releasing the nested ArrayBuilders. /// </summary> private ArrayBuilder <DeconstructionVariable> BindDeconstructionDeclarationLocals(VariableComponentAssignmentSyntax node, TypeSyntax closestTypeSyntax, DiagnosticBag diagnostics) { var deconstructionVariable = BindDeconstructionDeclarationLocals(node.VariableComponent, diagnostics); Debug.Assert(deconstructionVariable.HasNestedVariables); return(deconstructionVariable.NestedVariables); }
/// <summary> /// Prepares locals corresponding to the variables of the declaration. /// The locals are kept in a tree which captures the nesting of variables. /// Each local is either a simple local (when its type is known) or a deconstruction local pending inference. /// The caller is responsible for releasing the nested ArrayBuilders. /// </summary> private ArrayBuilder<DeconstructionVariable> BindDeconstructionDeclarationLocals(VariableComponentAssignmentSyntax node, TypeSyntax closestTypeSyntax, DiagnosticBag diagnostics) { var deconstructionVariable = BindDeconstructionDeclarationLocals(node.VariableComponent, diagnostics); Debug.Assert(deconstructionVariable.HasNestedVariables); return deconstructionVariable.NestedVariables; }
private IEnumerable<TypeInferenceInfo> InferTypeInVariableComponentAssignment( VariableComponentAssignmentSyntax variableComponentAssigment, ExpressionSyntax expression) { if (expression == variableComponentAssigment.Value) { var variableComponent = variableComponentAssigment.VariableComponent; if (variableComponent.IsKind(SyntaxKind.TypedVariableComponent)) { var typedVariable = (TypedVariableComponentSyntax)variableComponent; return GetTypes(typedVariable.Type); } else if (variableComponent.IsKind(SyntaxKind.ParenthesizedVariableComponent)) { // We have something of the form: // (int a, int b) = ... // // This is a deconstruction, and a decent deconstructable type we can infer here // is ValueTuple<int,int>. var parenthesizedVariable = (ParenthesizedVariableComponentSyntax)variableComponent; var tupleType = GetTupleType(parenthesizedVariable); if (tupleType != null) { return SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(tupleType)); } } } return SpecializedCollections.EmptyEnumerable<TypeInferenceInfo>(); }