1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Fix logic bugs caught by better elseif checks

This commit is contained in:
Matt Brown 2023-02-03 00:30:32 -05:00
parent 54cd529642
commit 234787bcd6
4 changed files with 11 additions and 13 deletions

View File

@ -459,7 +459,6 @@
<code><![CDATA[$combination->array_type_params[1]]]></code>
<code><![CDATA[$combination->array_type_params[1]]]></code>
<code><![CDATA[$combination->array_type_params[1]]]></code>
<code><![CDATA[$combination->array_type_params[1]]]></code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/Type/TypeExpander.php">

View File

@ -2434,7 +2434,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer
$storage->name,
),
);
} elseif ($case_storage->value !== null && $storage->enum_type !== null) {
} elseif ($case_storage->value !== null) {
if ((is_int($case_storage->value) && $storage->enum_type === 'string')
|| (is_string($case_storage->value) && $storage->enum_type === 'int')
) {

View File

@ -144,11 +144,10 @@ class ClassTemplateParamCollector
$template_result,
);
$class_template_params[$type_name][$class_storage->name]
= $output_type_extends ?? Type::getMixed();
}
if (!isset($class_template_params[$type_name][$class_storage->name])) {
$class_template_params[$type_name] = [
$class_storage->name => $output_type_extends ?? Type::getMixed(),
];
} else {
$class_template_params[$type_name] = [$class_storage->name => Type::getMixed()];
}
}

View File

@ -362,9 +362,11 @@ class TypeCombiner
$new_types[] = $type->setFromDocblock($from_docblock);
}
if (!$new_types && !$has_never) {
throw new UnexpectedValueException('There should be types here');
} elseif (!$new_types && $has_never) {
if (!$new_types) {
if (!$has_never) {
throw new UnexpectedValueException('There should be types here');
}
$union_type = Type::getNever($from_docblock);
} else {
$union_type = new Union($new_types);
@ -1351,9 +1353,7 @@ class TypeCombiner
if (!$combination->array_type_params || $combination->array_type_params[1]->isNever()) {
if (!$overwrite_empty_array
&& ($combination->array_type_params
&& ($combination->array_type_params[1]->isNever()
|| $combination->array_type_params[1]->isMixed()))
&& $combination->array_type_params
) {
foreach ($combination->objectlike_entries as &$objectlike_entry) {
$objectlike_entry = $objectlike_entry->setPossiblyUndefined(true);