@@ -115,25 +115,27 @@ public static BoundDecisionDag CreateDecisionDagForIsPattern(
115115 SyntaxNode syntax ,
116116 BoundExpression inputExpression ,
117117 BoundPattern pattern ,
118+ bool hasUnionMatching ,
118119 LabelSymbol whenTrueLabel ,
119120 LabelSymbol whenFalseLabel ,
120121 BindingDiagnosticBag diagnostics ,
121122 bool forLowering = false )
122123 {
123124 var builder = new DecisionDagBuilder ( compilation , defaultLabel : whenFalseLabel , forLowering , diagnostics ) ;
124- return builder . CreateDecisionDagForIsPattern ( syntax , inputExpression , pattern , whenTrueLabel ) ;
125+ return builder . CreateDecisionDagForIsPattern ( syntax , inputExpression , pattern , hasUnionMatching , whenTrueLabel ) ;
125126 }
126127
127128 private BoundDecisionDag CreateDecisionDagForIsPattern (
128129 SyntaxNode syntax ,
129130 BoundExpression inputExpression ,
130131 BoundPattern pattern ,
132+ bool hasUnionMatching ,
131133 LabelSymbol whenTrueLabel )
132134 {
133135 var rootIdentifier = BoundDagTemp . ForOriginalInput ( inputExpression ) ;
134136
135137 using var builder = TemporaryArray < StateForCase > . Empty ;
136- builder . Add ( MakeTestsForPattern ( index : 1 , pattern . Syntax , rootIdentifier , pattern , whenClause : null , whenTrueLabel ) ) ;
138+ builder . Add ( MakeTestsForPattern ( index : 1 , pattern . Syntax , rootIdentifier , pattern , hasUnionMatching , whenClause : null , whenTrueLabel ) ) ;
137139
138140 return MakeBoundDecisionDag ( syntax , ref builder . AsRef ( ) ) ;
139141 }
@@ -152,7 +154,7 @@ private BoundDecisionDag CreateDecisionDagForSwitchStatement(
152154 {
153155 if ( label . Syntax . Kind ( ) != SyntaxKind . DefaultSwitchLabel )
154156 {
155- builder . Add ( MakeTestsForPattern ( ++ i , label . Syntax , rootIdentifier , label . Pattern , label . WhenClause , label . Label ) ) ;
157+ builder . Add ( MakeTestsForPattern ( ++ i , label . Syntax , rootIdentifier , label . Pattern , label . HasUnionMatching , label . WhenClause , label . Label ) ) ;
156158 }
157159 }
158160 }
@@ -172,7 +174,7 @@ private BoundDecisionDag CreateDecisionDagForSwitchExpression(
172174 int i = 0 ;
173175 using var builder = TemporaryArray < StateForCase > . GetInstance ( switchArms . Length ) ;
174176 foreach ( BoundSwitchExpressionArm arm in switchArms )
175- builder . Add ( MakeTestsForPattern ( ++ i , arm . Syntax , rootIdentifier , arm . Pattern , arm . WhenClause , arm . Label ) ) ;
177+ builder . Add ( MakeTestsForPattern ( ++ i , arm . Syntax , rootIdentifier , arm . Pattern , arm . HasUnionMatching , arm . WhenClause , arm . Label ) ) ;
176178
177179 return MakeBoundDecisionDag ( syntax , ref builder . AsRef ( ) ) ;
178180 }
@@ -185,9 +187,15 @@ private StateForCase MakeTestsForPattern(
185187 SyntaxNode syntax ,
186188 BoundDagTemp input ,
187189 BoundPattern pattern ,
190+ bool hasUnionMatching ,
188191 BoundExpression ? whenClause ,
189192 LabelSymbol label )
190193 {
194+ if ( hasUnionMatching )
195+ {
196+ pattern = UnionMatchingRewriter . Rewrite ( _compilation , pattern ) ;
197+ }
198+
191199 Tests tests = MakeAndSimplifyTestsAndBindings ( input , pattern , out ImmutableArray < BoundPatternBinding > bindings ) ;
192200 return new StateForCase ( index , syntax , tests , bindings , whenClause , label ) ;
193201 }
@@ -330,6 +338,7 @@ private Tests MakeTestsAndBindings(
330338 out BoundDagTemp output ,
331339 ArrayBuilder < BoundPatternBinding > bindings )
332340 {
341+ Debug . Assert ( ! pattern . IsUnionMatching ) ;
333342 Debug . Assert ( pattern . HasErrors || pattern . InputType . Equals ( input . Type , TypeCompareKind . AllIgnoreOptions ) || pattern . InputType . IsErrorType ( ) ) ;
334343 switch ( pattern )
335344 {
0 commit comments