mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Do not widen type to mixed
and lose the existing type information when an Any
assertion is used.
Fixes #8084.
This commit is contained in:
parent
d957ff2015
commit
05f28ce8cd
@ -293,6 +293,10 @@ class AssertionReconciler extends Reconciler
|
||||
|
||||
$old_var_type_string = $existing_var_type->getId();
|
||||
|
||||
if ($new_type_part instanceof TMixed) {
|
||||
return $existing_var_type;
|
||||
}
|
||||
|
||||
$new_type_has_interface = false;
|
||||
|
||||
if ($new_type_part->isObjectType()) {
|
||||
|
@ -188,6 +188,24 @@ class IssetTest extends TestCase
|
||||
return $arr[$b];
|
||||
}',
|
||||
],
|
||||
'issetWithCalculatedKeyAndEqualComparison' => [
|
||||
'code' => '<?php
|
||||
/** @var array<string, string> $array */
|
||||
$array = [];
|
||||
|
||||
function sameString(string $string): string {
|
||||
return $string;
|
||||
}
|
||||
|
||||
if (isset($array[sameString("key")]) === false) {
|
||||
throw new \LogicException("No such key");
|
||||
}
|
||||
$value = $array[sameString("key")];
|
||||
',
|
||||
'assertions' => [
|
||||
'$value' => 'string',
|
||||
],
|
||||
],
|
||||
'issetArrayOffsetConditionalCreationWithInt' => [
|
||||
'code' => '<?php
|
||||
/** @param array<int, string> $arr */
|
||||
|
@ -9,6 +9,7 @@ use Psalm\Internal\Provider\NodeDataProvider;
|
||||
use Psalm\Internal\Type\AssertionReconciler;
|
||||
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
|
||||
use Psalm\Storage\Assertion;
|
||||
use Psalm\Storage\Assertion\Any;
|
||||
use Psalm\Storage\Assertion\Falsy;
|
||||
use Psalm\Storage\Assertion\IsIdentical;
|
||||
use Psalm\Storage\Assertion\IsLooselyEqual;
|
||||
@ -179,6 +180,7 @@ class ReconcilerTest extends TestCase
|
||||
'SimpleXMLElementNotAlwaysTruthy2' => ['SimpleXMLElement', new Falsy(), 'SimpleXMLElement'],
|
||||
'SimpleXMLIteratorNotAlwaysTruthy' => ['SimpleXMLIterator', new Truthy(), 'SimpleXMLIterator'],
|
||||
'SimpleXMLIteratorNotAlwaysTruthy2' => ['SimpleXMLIterator', new Falsy(), 'SimpleXMLIterator'],
|
||||
'stringWithAny' => ['string', new Any(), 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user