mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Keep HasArrayKey logic only for class strings
This commit is contained in:
parent
4c47d50d91
commit
a154d962f0
@ -75,6 +75,7 @@ use Psalm\Type\Union;
|
|||||||
|
|
||||||
use function array_map;
|
use function array_map;
|
||||||
use function array_merge;
|
use function array_merge;
|
||||||
|
use function assert;
|
||||||
use function count;
|
use function count;
|
||||||
use function explode;
|
use function explode;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
@ -1903,36 +1904,23 @@ class SimpleAssertionReconciler extends Reconciler
|
|||||||
$types = $existing_var_type->getAtomicTypes();
|
$types = $existing_var_type->getAtomicTypes();
|
||||||
foreach ($types as &$atomic_type) {
|
foreach ($types as &$atomic_type) {
|
||||||
if ($atomic_type instanceof TKeyedArray) {
|
if ($atomic_type instanceof TKeyedArray) {
|
||||||
$is_class_string = false;
|
assert(strpos($assertion, '::class') === (strlen($assertion)-7));
|
||||||
|
|
||||||
if (strpos($assertion, '::class')) {
|
|
||||||
[$assertion] = explode('::', $assertion);
|
[$assertion] = explode('::', $assertion);
|
||||||
$is_class_string = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($atomic_type->properties[$assertion])) {
|
|
||||||
$atomic_type = $atomic_type->setProperties(array_merge(
|
|
||||||
$atomic_type->properties,
|
|
||||||
[
|
|
||||||
$assertion => $atomic_type->properties[$assertion]->setPossiblyUndefined(false)
|
|
||||||
]
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
$atomic_type = new TKeyedArray(
|
$atomic_type = new TKeyedArray(
|
||||||
array_merge(
|
array_merge(
|
||||||
$atomic_type->properties,
|
$atomic_type->properties,
|
||||||
[$assertion => Type::getMixed()]
|
[$assertion => Type::getMixed()]
|
||||||
),
|
),
|
||||||
$is_class_string ? array_merge(
|
array_merge(
|
||||||
$atomic_type->class_strings ?? [],
|
$atomic_type->class_strings ?? [],
|
||||||
[$assertion => true]
|
[$assertion => true]
|
||||||
) : $atomic_type->class_strings,
|
),
|
||||||
$atomic_type->fallback_params,
|
$atomic_type->fallback_params,
|
||||||
$atomic_type->is_list
|
$atomic_type->is_list
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unset($atomic_type);
|
unset($atomic_type);
|
||||||
return $existing_var_type->setTypes($types);
|
return $existing_var_type->setTypes($types);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ use Psalm\Storage\Assertion;
|
|||||||
use Psalm\Storage\Assertion\ArrayKeyExists;
|
use Psalm\Storage\Assertion\ArrayKeyExists;
|
||||||
use Psalm\Storage\Assertion\Empty_;
|
use Psalm\Storage\Assertion\Empty_;
|
||||||
use Psalm\Storage\Assertion\Falsy;
|
use Psalm\Storage\Assertion\Falsy;
|
||||||
|
use Psalm\Storage\Assertion\HasArrayKey;
|
||||||
use Psalm\Storage\Assertion\HasIntOrStringArrayAccess;
|
use Psalm\Storage\Assertion\HasIntOrStringArrayAccess;
|
||||||
use Psalm\Storage\Assertion\HasStringArrayAccess;
|
use Psalm\Storage\Assertion\HasStringArrayAccess;
|
||||||
use Psalm\Storage\Assertion\IsEqualIsset;
|
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);
|
$key_parts = self::breakUpPathIntoParts($nk);
|
||||||
|
|
||||||
if (count($key_parts) === 4
|
if (count($key_parts) === 4
|
||||||
&& $key_parts[1] === '['
|
&& $key_parts[1] === '['
|
||||||
&& $key_parts[2][0] !== '\''
|
&& $key_parts[2][0] !== '\''
|
||||||
&& !is_numeric($key_parts[2])
|
&& !is_numeric($key_parts[2])
|
||||||
|
&& strpos($key_parts[2], '::class') === (strlen($key_parts[2])-7)
|
||||||
) {
|
) {
|
||||||
if ($key_parts[0][0] === '$') {
|
if ($key_parts[0][0] === '$') {
|
||||||
if (isset($new_types[$key_parts[0]])) {
|
if (isset($new_types[$key_parts[0]])) {
|
||||||
@ -512,7 +514,7 @@ class Reconciler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user