Permalink
Browse files
Fix #2333 - don’t create array after empty check
- Loading branch information
Showing
with
19 additions
and
1 deletion.
-
+1
−1
src/Psalm/Type/Reconciler.php
-
+18
−0
tests/EmptyTest.php
|
@@ -273,7 +273,7 @@ public static function reconcileKeyedTypes( |
|
|
if ($type_changed || $failed_reconciliation) { |
|
|
$changed_var_ids[] = $key; |
|
|
|
|
|
if (substr($key, -1) === ']' && !$has_inverted_isset) { |
|
|
if (substr($key, -1) === ']' && !$has_inverted_isset && !$has_empty) { |
|
|
$key_parts = self::breakUpPathIntoParts($key); |
|
|
self::adjustObjectLikeType( |
|
|
$key_parts, |
|
|
|
@@ -402,6 +402,24 @@ function foo(bool $b) : void { |
|
|
}', |
|
|
'error_message' => 'InvalidArgument', |
|
|
], |
|
|
'preventEmptyCreatingArray' => [ |
|
|
'<?php |
|
|
/** @return array{a:mixed} */ |
|
|
function foo(array $r) { |
|
|
if (!empty($r["a"])) {} |
|
|
return $r; |
|
|
}', |
|
|
'error_message' => 'MixedReturnTypeCoercion' |
|
|
], |
|
|
'preventEmptyEquivalentCreatingArray' => [ |
|
|
'<?php |
|
|
/** @return array{a:mixed} */ |
|
|
function foo(array $r) { |
|
|
if (isset($r["a"]) && $r["a"]) {} |
|
|
return $r; |
|
|
}', |
|
|
'error_message' => 'MixedReturnTypeCoercion' |
|
|
], |
|
|
]; |
|
|
} |
|
|
} |
0 comments on commit
d5b90f6