@@ -3217,7 +3217,6 @@ public function filterBySpecifiedTypes(SpecifiedTypes $specifiedTypes): self
32173217 continue ;
32183218 }
32193219
3220- // Pass 1: exact matching via equals()
32213220 foreach ($ conditionalExpressions as $ conditionalExpression ) {
32223221 foreach ($ conditionalExpression ->getConditionExpressionTypeHolders () as $ holderExprString => $ conditionalTypeHolder ) {
32233222 if (!array_key_exists ($ holderExprString , $ specifiedExpressions ) || !$ specifiedExpressions [$ holderExprString ]->equals ($ conditionalTypeHolder )) {
@@ -3229,31 +3228,26 @@ public function filterBySpecifiedTypes(SpecifiedTypes $specifiedTypes): self
32293228 $ specifiedExpressions [$ conditionalExprString ] = $ conditionalExpression ->getTypeHolder ();
32303229 }
32313230
3232- // Pass 2: use isSuperTypeOf for condition matching
3233- // This handles cases where the condition type is broader than the
3234- // narrowed type — e.g. 'value1'|'value2' (condition) won't match
3235- // 'value1' (narrowed) via equals(), but should match via
3236- // isSuperTypeOf. Only attempted when pass 1 found no matches, to
3237- // avoid conflicts with broader conditions that have lower certainty
3238- // from scope merging.
3239- if (!array_key_exists ($ conditionalExprString , $ conditions )) {
3240- foreach ($ conditionalExpressions as $ conditionalExpression ) {
3241- foreach ($ conditionalExpression ->getConditionExpressionTypeHolders () as $ holderExprString => $ conditionalTypeHolder ) {
3242- if (!array_key_exists ($ holderExprString , $ specifiedExpressions )) {
3243- continue 2 ;
3244- }
3245- $ specifiedHolder = $ specifiedExpressions [$ holderExprString ];
3246- if (!$ specifiedHolder ->getCertainty ()->equals ($ conditionalTypeHolder ->getCertainty ())) {
3247- continue 2 ;
3248- }
3249- if (!$ conditionalTypeHolder ->getType ()->isSuperTypeOf ($ specifiedHolder ->getType ())->yes ()) {
3250- continue 2 ;
3251- }
3252- }
3231+ if (array_key_exists ($ conditionalExprString , $ conditions )) {
3232+ continue ;
3233+ }
32533234
3254- $ conditions [$ conditionalExprString ][] = $ conditionalExpression ;
3255- $ specifiedExpressions [$ conditionalExprString ] = $ conditionalExpression ->getTypeHolder ();
3235+ foreach ($ conditionalExpressions as $ conditionalExpression ) {
3236+ foreach ($ conditionalExpression ->getConditionExpressionTypeHolders () as $ holderExprString => $ conditionalTypeHolder ) {
3237+ if (!array_key_exists ($ holderExprString , $ specifiedExpressions )) {
3238+ continue 2 ;
3239+ }
3240+ $ specifiedHolder = $ specifiedExpressions [$ holderExprString ];
3241+ if (!$ specifiedHolder ->getCertainty ()->equals ($ conditionalTypeHolder ->getCertainty ())) {
3242+ continue 2 ;
3243+ }
3244+ if (!$ conditionalTypeHolder ->getType ()->isSuperTypeOf ($ specifiedHolder ->getType ())->yes ()) {
3245+ continue 2 ;
3246+ }
32563247 }
3248+
3249+ $ conditions [$ conditionalExprString ][] = $ conditionalExpression ;
3250+ $ specifiedExpressions [$ conditionalExprString ] = $ conditionalExpression ->getTypeHolder ();
32573251 }
32583252 }
32593253 }
0 commit comments