@@ -240,7 +240,9 @@ public function specifyTypesInCondition(
240
240
}
241
241
}
242
242
243
+ $ leftType = $ scope ->getType ($ expr ->left );
243
244
$ rightType = $ scope ->getType ($ expr ->right );
245
+
244
246
if (
245
247
$ expr ->left instanceof ClassConstFetch &&
246
248
$ expr ->left ->class instanceof Expr &&
@@ -259,71 +261,71 @@ public function specifyTypesInCondition(
259
261
);
260
262
}
261
263
262
- if ($ context ->true ()) {
263
- $ type = TypeCombinator::intersect ($ scope ->getType ($ expr ->right ), $ scope ->getType ($ expr ->left ));
264
- $ leftTypes = $ this ->create ($ expr ->left , $ type , $ context , false , $ scope );
265
- $ rightTypes = $ this ->create ($ expr ->right , $ type , $ context , false , $ scope );
266
- return $ leftTypes ->unionWith ($ rightTypes );
264
+ $ types = null ;
267
265
268
- } elseif ($ context ->false ()) {
269
- $ identicalType = $ scope ->getType ($ expr );
270
- if ($ identicalType instanceof ConstantBooleanType) {
271
- $ never = new NeverType ();
272
- $ contextForTypes = $ identicalType ->getValue () ? $ context ->negate () : $ context ;
273
- $ leftTypes = $ this ->create ($ expr ->left , $ never , $ contextForTypes , false , $ scope );
274
- $ rightTypes = $ this ->create ($ expr ->right , $ never , $ contextForTypes , false , $ scope );
275
- return $ leftTypes ->unionWith ($ rightTypes );
266
+ if (
267
+ (
268
+ $ leftType instanceof ConstantType
269
+ && !$ expr ->right instanceof Node \Scalar
270
+ ) || $ leftType instanceof EnumCaseObjectType
271
+ ) {
272
+ $ types = $ this ->create (
273
+ $ expr ->right ,
274
+ $ leftType ,
275
+ $ context ,
276
+ false ,
277
+ $ scope ,
278
+ );
279
+ }
280
+
281
+ if (
282
+ (
283
+ $ rightType instanceof ConstantType
284
+ && !$ expr ->left instanceof Node \Scalar
285
+ ) || $ rightType instanceof EnumCaseObjectType
286
+ ) {
287
+ $ leftTypes = $ this ->create (
288
+ $ expr ->left ,
289
+ $ rightType ,
290
+ $ context ,
291
+ false ,
292
+ $ scope ,
293
+ );
294
+ if ($ types !== null ) {
295
+ $ types = $ types ->unionWith ($ leftTypes );
296
+ } else {
297
+ $ types = $ leftTypes ;
276
298
}
299
+ }
277
300
278
- $ exprLeftType = $ scope ->getType ($ expr ->left );
279
- $ exprRightType = $ scope ->getType ($ expr ->right );
301
+ if ($ types !== null ) {
302
+ return $ types ;
303
+ }
280
304
281
- $ types = null ;
305
+ $ identicalType = $ scope ->getType ($ expr );
306
+ if ($ identicalType instanceof ConstantBooleanType && $ context ->false ()) {
307
+ $ never = new NeverType ();
308
+ $ contextForTypes = $ identicalType ->getValue () ? $ context ->negate () : $ context ;
309
+ $ leftTypes = $ this ->create ($ expr ->left , $ never , $ contextForTypes , false , $ scope );
310
+ $ rightTypes = $ this ->create ($ expr ->right , $ never , $ contextForTypes , false , $ scope );
311
+ return $ leftTypes ->unionWith ($ rightTypes );
312
+ }
282
313
283
- if (
284
- (
285
- $ exprLeftType instanceof ConstantType
286
- && !$ expr ->right instanceof Node \Scalar
287
- ) || $ exprLeftType instanceof EnumCaseObjectType
288
- ) {
289
- $ types = $ this ->create (
290
- $ expr ->right ,
291
- $ exprLeftType ,
292
- $ context ,
293
- false ,
294
- $ scope ,
295
- );
296
- }
297
- if (
298
- (
299
- $ exprRightType instanceof ConstantType
300
- && !$ expr ->left instanceof Node \Scalar
301
- ) || $ exprRightType instanceof EnumCaseObjectType
302
- ) {
303
- $ leftType = $ this ->create (
304
- $ expr ->left ,
305
- $ exprRightType ,
306
- $ context ,
307
- false ,
308
- $ scope ,
309
- );
310
- if ($ types !== null ) {
311
- $ types = $ types ->unionWith ($ leftType );
312
- } else {
313
- $ types = $ leftType ;
314
- }
315
- }
314
+ if (
315
+ $ expr ->left instanceof Expr \Variable || $ expr ->right instanceof Expr \Variable
316
+ || $ expr ->left instanceof Node \Scalar || $ expr ->right instanceof Node \Scalar
317
+ ) {
318
+ if ($ context ->true ()) {
319
+ $ type = TypeCombinator::intersect ($ scope ->getType ($ expr ->right ), $ scope ->getType ($ expr ->left ));
320
+ $ leftTypes = $ this ->create ($ expr ->left , $ type , $ context , false , $ scope );
321
+ $ rightTypes = $ this ->create ($ expr ->right , $ type , $ context , false , $ scope );
322
+ return $ leftTypes ->unionWith ($ rightTypes );
316
323
317
- if ($ types !== null ) {
318
- return $ types ;
319
324
}
320
325
321
- if ($ expr ->left instanceof Expr \Variable && $ expr ->right instanceof Expr \Variable) {
322
- return $ this ->create ($ expr ->left , $ exprLeftType , $ context , false , $ scope )->normalize ($ scope )
323
- ->intersectWith ($ this ->create ($ expr ->right , $ exprRightType , $ context , false , $ scope )->normalize ($ scope ));
324
- }
326
+ return $ this ->create ($ expr ->left , $ leftType , $ context , false , $ scope )->normalize ($ scope )
327
+ ->intersectWith ($ this ->create ($ expr ->right , $ rightType , $ context , false , $ scope )->normalize ($ scope ));
325
328
}
326
-
327
329
} elseif ($ expr instanceof Node \Expr \BinaryOp \NotIdentical) {
328
330
return $ this ->specifyTypesInCondition (
329
331
$ scope ,
@@ -443,9 +445,14 @@ public function specifyTypesInCondition(
443
445
$ leftTypes = $ this ->create ($ expr ->left , $ leftType , $ context , false , $ scope );
444
446
$ rightTypes = $ this ->create ($ expr ->right , $ rightType , $ context , false , $ scope );
445
447
446
- return $ context ->true ()
447
- ? $ leftTypes ->unionWith ($ rightTypes )
448
- : $ leftTypes ->normalize ($ scope )->intersectWith ($ rightTypes ->normalize ($ scope ));
448
+ if (
449
+ $ expr ->left instanceof Expr \Variable || $ expr ->right instanceof Expr \Variable
450
+ || $ expr ->left instanceof Node \Scalar || $ expr ->right instanceof Node \Scalar
451
+ ) {
452
+ return $ context ->true ()
453
+ ? $ leftTypes ->unionWith ($ rightTypes )
454
+ : $ leftTypes ->normalize ($ scope )->intersectWith ($ rightTypes ->normalize ($ scope ));
455
+ }
449
456
} elseif ($ expr instanceof Node \Expr \BinaryOp \NotEqual) {
450
457
return $ this ->specifyTypesInCondition (
451
458
$ scope ,
0 commit comments