Fix one more match regression · phpstan/phpstan-src@4628ff9

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -4217,25 +4217,28 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto

42174217
42184218

// Pre-validate all conditions before processing to avoid

42194219

// partial consumption of enum cases when a later condition

4220-

// causes the arm to be skipped

4220+

// causes the arm to be skipped.

4221+

// Use break instead of continue to stop fast-path processing

4222+

// entirely - subsequent arms must also go through the slow

4223+

// path to preserve correct evaluation order.

42214224

foreach ($arm->conds as $cond) {

42224225

if (!$cond instanceof Expr\ClassConstFetch) {

4223-

continue 2;

4226+

break 2;

42244227

}

42254228

if (!$cond->class instanceof Name) {

4226-

continue 2;

4229+

break 2;

42274230

}

42284231

if (!$cond->name instanceof Node\Identifier) {

4229-

continue 2;

4232+

break 2;

42304233

}

42314234

$fetchedClassName = $scope->resolveName($cond->class);

42324235

$loweredFetchedClassName = strtolower($fetchedClassName);

42334236

if (!array_key_exists($loweredFetchedClassName, $indexedEnumCases)) {

4234-

continue 2;

4237+

break 2;

42354238

}

42364239

$caseName = $cond->name->toString();

42374240

if (!array_key_exists($caseName, $indexedEnumCases[$loweredFetchedClassName])) {

4238-

continue 2;

4241+

break 2;

42394242

}

42404243

}

42414244
Original file line numberDiff line numberDiff line change

@@ -141,22 +141,17 @@ public function testEnums(): void

141141

85,

142142

],

143143

[

144-

'Match arm comparison between *NEVER* and MatchEnums\DifferentEnum::ONE is always false.',

144+

'Match arm comparison between MatchEnums\Foo::THREE|MatchEnums\Foo::TWO and MatchEnums\DifferentEnum::ONE is always false.',

145145

95,

146146

],

147147

[

148148

'Match arm comparison between MatchEnums\Foo and MatchEnums\Foo::ONE is always false.',

149149

104,

150150

],

151151

[

152-

'Match arm comparison between *NEVER* and MatchEnums\DifferentEnum::ONE is always false.',

152+

'Match arm comparison between MatchEnums\Foo::THREE|MatchEnums\Foo::TWO and MatchEnums\DifferentEnum::ONE is always false.',

153153

113,

154154

],

155-

[

156-

'Match arm comparison between MatchEnums\Foo::ONE and MatchEnums\Foo::ONE is always true.',

157-

113,

158-

'Remove remaining cases below this one and this error will disappear too.',

159-

],

160155

]);

161156

}

162157