@@ -517,7 +517,7 @@ private BoundPattern BindDeconstructionPattern(DeconstructionPatternSyntax node,
517517 TypeSyntax typeSyntax = node . Type ;
518518 TypeSymbol declType = BindRecursivePatternType ( typeSyntax , inputType , diagnostics , ref hasErrors , out BoundTypeExpression boundDeclType ) ;
519519
520- var patterns = ArrayBuilder < BoundPattern > . GetInstance ( node . SubPatterns . Count ) ;
520+ var patterns = ArrayBuilder < BoundSubpattern > . GetInstance ( node . SubPatterns . Count ) ;
521521 MethodSymbol deconstructMethod = null ;
522522 if ( declType . IsTupleType )
523523 {
@@ -534,14 +534,19 @@ private BoundPattern BindDeconstructionPattern(DeconstructionPatternSyntax node,
534534 var subPattern = node . SubPatterns [ i ] ;
535535 bool isError = i >= elementTypes . Length ;
536536 TypeSymbol elementType = isError ? CreateErrorType ( ) : elementTypes [ i ] ;
537+ FieldSymbol foundField = null ;
537538 if ( subPattern . NameColon != null )
538539 {
539540 string name = subPattern . NameColon . Name . Identifier . ValueText ;
540- FieldSymbol foundField = CheckIsTupleElement ( subPattern . NameColon . Name , ( NamedTypeSymbol ) declType , name , i , diagnostics ) ;
541+ foundField = CheckIsTupleElement ( subPattern . NameColon . Name , ( NamedTypeSymbol ) declType , name , i , diagnostics ) ;
541542 // PROTOTYPE(patterns2): Should the tuple field binding for the name be stored somewhere in the node?
542543
543544 }
544- BoundPattern boundSubpattern = BindPattern ( subPattern . Pattern , elementType , isError , diagnostics ) ;
545+ BoundSubpattern boundSubpattern = new BoundSubpattern (
546+ subPattern ,
547+ foundField ,
548+ BindPattern ( subPattern . Pattern , elementType , isError , diagnostics )
549+ ) ;
545550 patterns . Add ( boundSubpattern ) ;
546551 }
547552 }
@@ -565,26 +570,32 @@ private BoundPattern BindDeconstructionPattern(DeconstructionPatternSyntax node,
565570 var subPattern = node . SubPatterns [ i ] ;
566571 bool isError = outPlaceholders . IsDefaultOrEmpty || i >= outPlaceholders . Length ;
567572 TypeSymbol elementType = isError ? CreateErrorType ( ) : outPlaceholders [ i ] . Type ;
573+ ParameterSymbol parameter = null ;
568574 if ( subPattern . NameColon != null && ! isError )
569575 {
570576 // Check that the given name is the same as the corresponding parameter of the method.
571577 string name = subPattern . NameColon . Name . Identifier . ValueText ;
572578 int parameterIndex = i + skippedExtensionParameters ;
573- string parameterName = deconstructMethod . Parameters [ parameterIndex ] . Name ;
579+ parameter = deconstructMethod . Parameters [ parameterIndex ] ;
580+ string parameterName = parameter . Name ;
574581 if ( name != parameterName )
575582 {
576583 diagnostics . Add ( ErrorCode . ERR_DeconstructParameterNameMismatch , subPattern . NameColon . Name . Location , name , parameterName ) ;
577584 }
578585 // PROTOTYPE(patterns2): Should the parameter binding for the name be stored somewhere in the node?
579586 }
580- BoundPattern boundSubpattern = BindPattern ( subPattern . Pattern , elementType , isError , diagnostics ) ;
587+ BoundSubpattern boundSubpattern = new BoundSubpattern (
588+ subPattern ,
589+ parameter ,
590+ BindPattern ( subPattern . Pattern , elementType , isError , diagnostics )
591+ ) ;
581592 patterns . Add ( boundSubpattern ) ;
582593 }
583594
584595 // PROTOTYPE(patterns2): If no Deconstruct method is found, try casting to `ITuple`.
585596 }
586597
587- ImmutableArray < ( Symbol property , BoundPattern pattern ) > propertiesOpt = default ;
598+ ImmutableArray < BoundSubpattern > propertiesOpt = default ;
588599 if ( node . PropertySubpattern != null )
589600 {
590601 propertiesOpt = BindPropertySubpattern ( node . PropertySubpattern , declType , diagnostics , ref hasErrors ) ;
@@ -658,7 +669,7 @@ private BoundPattern BindVarDesignation(VarPatternSyntax node, VariableDesignati
658669 case SyntaxKind . ParenthesizedVariableDesignation :
659670 {
660671 var tupleDesignation = ( ParenthesizedVariableDesignationSyntax ) designation ;
661- var patterns = ArrayBuilder < BoundPattern > . GetInstance ( tupleDesignation . Variables . Count ) ;
672+ var subPatterns = ArrayBuilder < BoundSubpattern > . GetInstance ( tupleDesignation . Variables . Count ) ;
662673 MethodSymbol deconstructMethod = null ;
663674 if ( inputType . IsTupleType )
664675 {
@@ -676,7 +687,7 @@ private BoundPattern BindVarDesignation(VarPatternSyntax node, VariableDesignati
676687 bool isError = i >= elementTypes . Length ;
677688 TypeSymbol elementType = isError ? CreateErrorType ( ) : elementTypes [ i ] ;
678689 BoundPattern boundSubpattern = BindVarDesignation ( node , tupleDesignation . Variables [ i ] , elementType , isError , diagnostics ) ;
679- patterns . Add ( boundSubpattern ) ;
690+ subPatterns . Add ( new BoundSubpattern ( node , null , boundSubpattern ) ) ;
680691 }
681692 }
682693 else
@@ -692,16 +703,16 @@ private BoundPattern BindVarDesignation(VarPatternSyntax node, VariableDesignati
692703 {
693704 bool isError = outPlaceholders . IsDefaultOrEmpty || i >= outPlaceholders . Length ;
694705 TypeSymbol elementType = isError ? CreateErrorType ( ) : outPlaceholders [ i ] . Type ;
695- BoundPattern boundSubpattern = BindVarDesignation ( node , tupleDesignation . Variables [ i ] , elementType , isError , diagnostics ) ;
696- patterns . Add ( boundSubpattern ) ;
706+ BoundPattern pattern = BindVarDesignation ( node , tupleDesignation . Variables [ i ] , elementType , isError , diagnostics ) ;
707+ subPatterns . Add ( new BoundSubpattern ( node , null , pattern ) ) ;
697708 }
698709
699710 // PROTOTYPE(patterns2): If no Deconstruct method is found, try casting to `ITuple`.
700711 }
701712
702713 return new BoundRecursivePattern (
703714 syntax : node , declaredType : null , inputType : inputType , deconstructMethodOpt : deconstructMethod ,
704- deconstruction : patterns . ToImmutableAndFree ( ) , propertiesOpt : default , variable : null , variableAccess : null , hasErrors : hasErrors ) ;
715+ deconstruction : subPatterns . ToImmutableAndFree ( ) , propertiesOpt : default , variable : null , variableAccess : null , hasErrors : hasErrors ) ;
705716 }
706717 default :
707718 {
@@ -714,20 +725,20 @@ private BoundPattern BindPropertyPattern(PropertyPatternSyntax node, TypeSymbol
714725 {
715726 TypeSyntax typeSyntax = node . Type ;
716727 TypeSymbol declType = BindRecursivePatternType ( typeSyntax , inputType , diagnostics , ref hasErrors , out BoundTypeExpression boundDeclType ) ;
717- ImmutableArray < ( Symbol property , BoundPattern pattern ) > propertiesOpt = BindPropertySubpattern ( node . PropertySubpattern , declType , diagnostics , ref hasErrors ) ;
728+ ImmutableArray < BoundSubpattern > propertiesOpt = BindPropertySubpattern ( node . PropertySubpattern , declType , diagnostics , ref hasErrors ) ;
718729 BindPatternDesignation ( node , node . Designation , declType , typeSyntax , diagnostics , ref hasErrors , out Symbol variableSymbol , out BoundExpression variableAccess ) ;
719730 return new BoundRecursivePattern (
720731 syntax : node , declaredType : boundDeclType , inputType : inputType , deconstructMethodOpt : null ,
721732 deconstruction : default , propertiesOpt : propertiesOpt , variable : variableSymbol , variableAccess : variableAccess , hasErrors : hasErrors ) ;
722733 }
723734
724- ImmutableArray < ( Symbol property , BoundPattern pattern ) > BindPropertySubpattern (
735+ ImmutableArray < BoundSubpattern > BindPropertySubpattern (
725736 PropertySubpatternSyntax node ,
726737 TypeSymbol inputType ,
727738 DiagnosticBag diagnostics ,
728739 ref bool hasErrors )
729740 {
730- var builder = ArrayBuilder < ( Symbol property , BoundPattern pattern ) > . GetInstance ( node . SubPatterns . Count ) ;
741+ var builder = ArrayBuilder < BoundSubpattern > . GetInstance ( node . SubPatterns . Count ) ;
731742 foreach ( SubpatternElementSyntax p in node . SubPatterns )
732743 {
733744 IdentifierNameSyntax name = p . NameColon ? . Name ;
@@ -750,7 +761,7 @@ private BoundPattern BindPropertyPattern(PropertyPatternSyntax node, TypeSymbol
750761 }
751762
752763 BoundPattern boundPattern = BindPattern ( pattern , memberType , hasErrors , diagnostics ) ;
753- builder . Add ( ( member , boundPattern ) ) ;
764+ builder . Add ( new BoundSubpattern ( pattern , member , boundPattern ) ) ;
754765 }
755766
756767 return builder . ToImmutableAndFree ( ) ;
0 commit comments