Skip to content
Permalink
Browse files

Fix #2333 - don’t create array after empty check

  • Loading branch information
muglug committed Nov 14, 2019
1 parent 8777c95 commit d5b90f6887ed4f4fa8f053b6a08a29c217911300
Showing with 19 additions and 1 deletion.
  1. +1 −1 src/Psalm/Type/Reconciler.php
  2. +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

Please sign in to comment.
You can’t perform that action at this time.