diff --git a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php index 7c69f3fa7..8a2ff9d1f 100644 --- a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php @@ -75,6 +75,7 @@ use Psalm\Type\Union; use function array_map; use function array_merge; +use function assert; use function count; use function explode; use function get_class; @@ -1903,34 +1904,21 @@ class SimpleAssertionReconciler extends Reconciler $types = $existing_var_type->getAtomicTypes(); foreach ($types as &$atomic_type) { if ($atomic_type instanceof TKeyedArray) { - $is_class_string = false; + assert(strpos($assertion, '::class') === (strlen($assertion)-7)); + [$assertion] = explode('::', $assertion); - if (strpos($assertion, '::class')) { - [$assertion] = explode('::', $assertion); - $is_class_string = true; - } - - if (isset($atomic_type->properties[$assertion])) { - $atomic_type = $atomic_type->setProperties(array_merge( + $atomic_type = new TKeyedArray( + array_merge( $atomic_type->properties, - [ - $assertion => $atomic_type->properties[$assertion]->setPossiblyUndefined(false) - ] - )); - } else { - $atomic_type = new TKeyedArray( - array_merge( - $atomic_type->properties, - [$assertion => Type::getMixed()] - ), - $is_class_string ? array_merge( - $atomic_type->class_strings ?? [], - [$assertion => true] - ) : $atomic_type->class_strings, - $atomic_type->fallback_params, - $atomic_type->is_list - ); - } + [$assertion => Type::getMixed()] + ), + array_merge( + $atomic_type->class_strings ?? [], + [$assertion => true] + ), + $atomic_type->fallback_params, + $atomic_type->is_list + ); } } unset($atomic_type); diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index 0baf92c57..62293693b 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -23,6 +23,7 @@ use Psalm\Storage\Assertion; use Psalm\Storage\Assertion\ArrayKeyExists; use Psalm\Storage\Assertion\Empty_; use Psalm\Storage\Assertion\Falsy; +use Psalm\Storage\Assertion\HasArrayKey; use Psalm\Storage\Assertion\HasIntOrStringArrayAccess; use Psalm\Storage\Assertion\HasStringArrayAccess; use Psalm\Storage\Assertion\IsEqualIsset; @@ -496,13 +497,14 @@ class Reconciler } } - /*if ($type[0][0] instanceof ArrayKeyExists) { + if ($type[0][0] instanceof ArrayKeyExists) { $key_parts = self::breakUpPathIntoParts($nk); if (count($key_parts) === 4 && $key_parts[1] === '[' && $key_parts[2][0] !== '\'' && !is_numeric($key_parts[2]) + && strpos($key_parts[2], '::class') === (strlen($key_parts[2])-7) ) { if ($key_parts[0][0] === '$') { if (isset($new_types[$key_parts[0]])) { @@ -512,7 +514,7 @@ class Reconciler } } } - }*/ + } } }