File tree 2 files changed +15
-3
lines changed
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -2067,7 +2067,6 @@ private static function reconcileFalsyOrEmpty(
2067
2067
$ did_remove_type = $ existing_var_type ->hasDefinitelyNumericType (false )
2068
2068
|| $ existing_var_type ->hasType ('iterable ' );
2069
2069
2070
-
2071
2070
if ($ existing_var_type ->hasMixed ()) {
2072
2071
if ($ existing_var_type ->isMixed ()
2073
2072
&& $ existing_var_atomic_types ['mixed ' ] instanceof Type \Atomic \TNonEmptyMixed
@@ -2334,7 +2333,9 @@ function (Type\Union $t) {
2334
2333
}
2335
2334
}
2336
2335
2337
- if (!$ did_remove_type || empty ($ existing_var_type ->getAtomicTypes ())) {
2336
+ if ((!$ did_remove_type || empty ($ existing_var_type ->getAtomicTypes ()))
2337
+ && ($ assertion !== 'empty ' || !$ existing_var_type ->possibly_undefined )
2338
+ ) {
2338
2339
if ($ key && $ code_location ) {
2339
2340
self ::triggerIssueForImpossible (
2340
2341
$ existing_var_type ,
@@ -2354,7 +2355,9 @@ function (Type\Union $t) {
2354
2355
2355
2356
$ failed_reconciliation = 2 ;
2356
2357
2357
- return Type::getMixed ();
2358
+ return $ assertion === 'empty ' && $ existing_var_type ->possibly_undefined
2359
+ ? Type::getEmpty ()
2360
+ : Type::getMixed ();
2358
2361
}
2359
2362
2360
2363
/**
Original file line number Diff line number Diff line change @@ -365,6 +365,15 @@ function f($p): bool {
365
365
return true;
366
366
} '
367
367
],
368
+ 'possiblyUndefinedArrayOffset ' => [
369
+ '<?php
370
+ $d = [];
371
+ if (!rand(0,1)) {
372
+ $d[0] = "a";
373
+ }
374
+
375
+ if (empty($d[0])) {} '
376
+ ],
368
377
];
369
378
}
370
379
You can’t perform that action at this time.
0 commit comments