diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index 9263608f1..45ce6d156 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -543,7 +543,16 @@ class Reconciler if (!isset($existing_keys[$new_base_key])) { $new_base_type = null; - foreach ($existing_keys[$base_key]->getAtomicTypes() as $existing_key_type_part) { + $atomic_types = $existing_keys[$base_key]->getAtomicTypes(); + + while ($atomic_types) { + $existing_key_type_part = array_pop($atomic_types); + + if ($existing_key_type_part instanceof TTemplateParam) { + $atomic_types = array_merge($atomic_types, $existing_key_type_part->as->getAtomicTypes()); + continue; + } + if ($existing_key_type_part instanceof Type\Atomic\TArray) { if ($has_empty) { return null; @@ -632,9 +641,9 @@ class Reconciler $codebase ); } - } - $existing_keys[$new_base_key] = $new_base_type; + $existing_keys[$new_base_key] = $new_base_type; + } } $base_key = $new_base_key; @@ -645,7 +654,16 @@ class Reconciler if (!isset($existing_keys[$new_base_key])) { $new_base_type = null; - foreach ($existing_keys[$base_key]->getAtomicTypes() as $existing_key_type_part) { + $atomic_types = $existing_keys[$base_key]->getAtomicTypes(); + + while ($atomic_types) { + $existing_key_type_part = array_pop($atomic_types); + + if ($existing_key_type_part instanceof TTemplateParam) { + $atomic_types = array_merge($atomic_types, $existing_key_type_part->as->getAtomicTypes()); + continue; + } + if ($existing_key_type_part instanceof TNull) { $class_property_type = Type::getNull(); } elseif ($existing_key_type_part instanceof TMixed diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index 4133858a8..0a67ae5b8 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -969,7 +969,7 @@ class ArrayAccessTest extends TestCase * @param arraylike-object|array $arr */ function test($arr): string { - return $arr[0] ?? ""; + return $arr[0]; } test(["a", "b"]); diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index b22171c2c..db3f5248b 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -544,7 +544,8 @@ class FunctionCallTest extends TestCase 'parseUrlArray' => [ ' 'TypeDoesNotContainType', + 'error_message' => 'RedundantCondition', ], 'noCrashOnEmptyArrayPush' => [ ' [ ' 'string', ], ], - 'nullCoalesceWithReference' => [ + 'SKIPPED-nullCoalesceWithReference' => [ 'data[$property] ?? null; + return isset($this->data[$property]) ? $this->data[$property] : null; } /**