1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

qa: resolving psalm issues

- remove unused variable
- add assertion to reduce possible types from `TEnumCase`
- use `TypeCombiner` to provide proper `Union` containing all literals

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
This commit is contained in:
Maximilian Bösing 2023-08-26 00:24:36 +02:00
parent cd3e294bfd
commit f93ac70a0a
No known key found for this signature in database
GPG Key ID: 9A8988C93CEC81A3
2 changed files with 4 additions and 3 deletions

View File

@ -2963,7 +2963,6 @@ class SimpleAssertionReconciler extends Reconciler
// For now, only enums are supported here
foreach ($assertion_type->type->getAtomicTypes() as $atomic_type) {
$class_name = null;
$enum_case_to_assert = null;
if ($atomic_type instanceof TClassConstant) {
$class_name = $atomic_type->fq_classlike_name;
@ -2990,6 +2989,7 @@ class SimpleAssertionReconciler extends Reconciler
// For value-of<MyBackedEnum>, the assertion is meant to return *ANY* value of *ANY* enum case
if ($enum_case_to_assert === null) {
foreach ($class_storage->enum_cases as $enum_case) {
assert($enum_case->value !== null, 'Verified enum type above, value can not contain `null` anymore.');
$reconciled_types[] = Type::getLiteral($enum_case->value);
}
@ -3001,10 +3001,11 @@ class SimpleAssertionReconciler extends Reconciler
return null;
}
assert($enum_case->value !== null, 'Verified enum type above, value can not contain `null` anymore.');
$reconciled_types[] = Type::getLiteral($enum_case->value);
}
return new Union($reconciled_types);
return TypeCombiner::combine($reconciled_types, $codebase, false, false);
}
/**

View File

@ -269,7 +269,7 @@ abstract class Type
return new TLiteralInt($value);
}
return new TLiteralString($value);
return TLiteralString::make($value);
}
public static function getString(?string $value = null): Union