14
14
use PhpParser \Node \Expr \FuncCall ;
15
15
use PhpParser \Node \Expr \Instanceof_ ;
16
16
use PhpParser \Node \Expr \MethodCall ;
17
- use PhpParser \Node \Expr \New_ ;
18
17
use PhpParser \Node \Expr \PropertyFetch ;
19
18
use PhpParser \Node \Expr \StaticCall ;
20
19
use PhpParser \Node \Expr \StaticPropertyFetch ;
@@ -258,14 +257,7 @@ public function specifyTypesInCondition(
258
257
$ context ,
259
258
);
260
259
}
261
-
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 );
267
-
268
- } elseif ($ context ->false ()) {
260
+ if ($ context ->false ()) {
269
261
$ identicalType = $ scope ->getType ($ expr );
270
262
if ($ identicalType instanceof ConstantBooleanType) {
271
263
$ never = new NeverType ();
@@ -274,18 +266,13 @@ public function specifyTypesInCondition(
274
266
$ rightTypes = $ this ->create ($ expr ->right , $ never , $ contextForTypes , false , $ scope );
275
267
return $ leftTypes ->unionWith ($ rightTypes );
276
268
}
269
+ }
277
270
278
- $ exprLeftType = $ scope ->getType ($ expr ->left );
279
- $ exprRightType = $ scope ->getType ($ expr ->right );
280
-
281
- $ types = null ;
282
-
283
- if (
284
- (
285
- $ exprLeftType instanceof ConstantType
286
- && !$ expr ->right instanceof Node \Scalar
287
- ) || $ exprLeftType instanceof EnumCaseObjectType
288
- ) {
271
+ $ types = null ;
272
+ $ exprLeftType = $ scope ->getType ($ expr ->left );
273
+ $ exprRightType = $ scope ->getType ($ expr ->right );
274
+ if ($ exprLeftType instanceof ConstantType || $ exprLeftType instanceof EnumCaseObjectType) {
275
+ if (!$ expr ->right instanceof Node \Scalar && !$ expr ->right instanceof Expr \Array_) {
289
276
$ types = $ this ->create (
290
277
$ expr ->right ,
291
278
$ exprLeftType ,
@@ -294,12 +281,9 @@ public function specifyTypesInCondition(
294
281
$ scope ,
295
282
);
296
283
}
297
- if (
298
- (
299
- $ exprRightType instanceof ConstantType
300
- && !$ expr ->left instanceof Node \Scalar
301
- ) || $ exprRightType instanceof EnumCaseObjectType
302
- ) {
284
+ }
285
+ if ($ exprRightType instanceof ConstantType || $ exprRightType instanceof EnumCaseObjectType) {
286
+ if ($ types === null || (!$ expr ->left instanceof Node \Scalar && !$ expr ->left instanceof Expr \Array_)) {
303
287
$ leftType = $ this ->create (
304
288
$ expr ->left ,
305
289
$ exprRightType ,
@@ -313,11 +297,26 @@ public function specifyTypesInCondition(
313
297
$ types = $ leftType ;
314
298
}
315
299
}
300
+ }
301
+
302
+ if ($ types !== null ) {
303
+ return $ types ;
304
+ }
316
305
317
- if ($ types !== null ) {
318
- return $ types ;
306
+ $ leftExprString = $ this ->printer ->prettyPrintExpr ($ expr ->left );
307
+ $ rightExprString = $ this ->printer ->prettyPrintExpr ($ expr ->right );
308
+ if ($ leftExprString === $ rightExprString ) {
309
+ if (!$ expr ->left instanceof Expr \Variable || !$ expr ->right instanceof Expr \Variable) {
310
+ return new SpecifiedTypes ();
319
311
}
312
+ }
320
313
314
+ if ($ context ->true ()) {
315
+ $ type = TypeCombinator::intersect ($ scope ->getType ($ expr ->right ), $ scope ->getType ($ expr ->left ));
316
+ $ leftTypes = $ this ->create ($ expr ->left , $ type , $ context , false , $ scope );
317
+ $ rightTypes = $ this ->create ($ expr ->right , $ type , $ context , false , $ scope );
318
+ return $ leftTypes ->unionWith ($ rightTypes );
319
+ } elseif ($ context ->false ()) {
321
320
return $ this ->create ($ expr ->left , $ exprLeftType , $ context , false , $ scope )->normalize ($ scope )
322
321
->intersectWith ($ this ->create ($ expr ->right , $ exprRightType , $ context , false , $ scope )->normalize ($ scope ));
323
322
}
@@ -981,7 +980,7 @@ public function create(
981
980
?Scope $ scope = null ,
982
981
): SpecifiedTypes
983
982
{
984
- if ($ expr instanceof New_ || $ expr instanceof Instanceof_ || $ expr instanceof Expr \List_ || $ expr instanceof VirtualNode) {
983
+ if ($ expr instanceof Instanceof_ || $ expr instanceof Expr \List_ || $ expr instanceof VirtualNode) {
985
984
return new SpecifiedTypes ();
986
985
}
987
986
0 commit comments