1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00
This commit is contained in:
Daniil Gentili 2022-12-02 18:22:33 +01:00
parent d4df856124
commit c80221344b
4 changed files with 10 additions and 4 deletions

View File

@ -1153,8 +1153,9 @@ class AssertionFinder
if (is_numeric($var_id) && null !== $property && !$is_function) {
$args = $expr->getArgs();
$var_id_int = (int) $var_id;
if (!array_key_exists($var_id, $args)) {
if (!array_key_exists($var_id_int, $args)) {
IssueBuffer::maybeAdd(
new InvalidDocblock(
'Variable '.$var_id.' is not an argument so cannot be asserted',
@ -1164,7 +1165,7 @@ class AssertionFinder
continue;
}
/** @var PhpParser\Node\Expr\Variable $arg_value */
$arg_value = $args[$var_id]->value;
$arg_value = $args[$var_id_int]->value;
$arg_var_id = ExpressionIdentifier::getExtendedVarId($arg_value, null, $source);

View File

@ -676,10 +676,9 @@ class StatementsAnalyzer extends SourceAnalyzer
}
foreach ($checked_types as [$check_type_line, $is_exact]) {
/** @var string|null $check_type_string (incorrectly inferred) */
[$checked_var, $check_type_string] = array_map('trim', explode('=', $check_type_line));
if ($check_type_string === null) {
if ($check_type_string === '') {
IssueBuffer::maybeAdd(
new InvalidDocblock(
"Invalid format for @psalm-check-type" . ($is_exact ? "-exact" : ""),

View File

@ -184,6 +184,8 @@ class TypeCombiner
$combined_param_types[] = Type::combineUnionTypes($array_param_type, $traversable_param_types[$i]);
}
assert(count($combined_param_types) <= 2);
$combination->value_types['iterable'] = new TIterable($combined_param_types);
$combination->array_type_params = [];
@ -236,6 +238,7 @@ class TypeCombiner
foreach ($combination->builtin_type_params as $generic_type => $generic_type_params) {
if ($generic_type === 'iterable') {
assert(count($generic_type_params) <= 2);
$new_types[] = new TIterable($generic_type_params);
} else {
/** @psalm-suppress ArgumentTypeCoercion Caused by the PropertyTypeCoercion above */

View File

@ -229,6 +229,8 @@ trait GenericTrait
);
}
assert(count($type_params) === 2);
return $type_params === $this->type_params ? null : $type_params;
}
@ -253,6 +255,7 @@ trait GenericTrait
$type_params[$offset] = $type_param;
}
assert(count($type_params) === 2);
return $type_params === $this->type_params ? null : $type_params;
}