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

Merge pull request #7288 from orklah/classconst4

resolve type alias and class const on UnionTypeComparator
This commit is contained in:
orklah 2022-01-04 00:22:06 +01:00 committed by GitHub
commit 68e50f56c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 4 deletions

View File

@ -362,7 +362,7 @@ class UnionTypeComparator
return false;
}
foreach ($container_type->getAtomicTypes() as $container_type_part) {
foreach (self::getTypeParts($codebase, $container_type) as $container_type_part) {
if ($container_type_part instanceof TNull && $ignore_null) {
continue;
}
@ -371,7 +371,7 @@ class UnionTypeComparator
continue;
}
foreach ($input_type->getAtomicTypes() as $input_type_part) {
foreach (self::getTypeParts($codebase, $input_type) as $input_type_part) {
$atomic_comparison_result = new TypeComparisonResult();
$is_atomic_contained_by = AtomicTypeComparator::isContainedBy(
$codebase,
@ -411,8 +411,8 @@ class UnionTypeComparator
return true;
}
foreach ($type1->getAtomicTypes() as $type1_part) {
foreach ($type2->getAtomicTypes() as $type2_part) {
foreach (self::getTypeParts($codebase, $type1) as $type1_part) {
foreach (self::getTypeParts($codebase, $type2) as $type2_part) {
//special cases for TIntRange because it can contain a part of the other type.
//For exemple int<0,1> and positive-int can be identical but none contain the other
if (($type1_part instanceof TIntRange && $type2_part instanceof TPositiveInt)) {

View File

@ -1200,6 +1200,36 @@ class ConstantTest extends TestCase
[],
'8.1'
],
'classConstWithParamOut' => [
'<?php
class Reconciler
{
public const RECONCILIATION_OK = 0;
public const RECONCILIATION_EMPTY = 1;
public static function reconcileKeyedTypes(): void
{
$failed_reconciliation = 0;
self::boo($failed_reconciliation);
if ($failed_reconciliation === self::RECONCILIATION_EMPTY) {
echo "ici";
}
}
/** @param-out Reconciler::RECONCILIATION_* $f */
public static function boo(
?int &$f = self::RECONCILIATION_OK
): void {
$f = self::RECONCILIATION_EMPTY;
}
}
Reconciler::reconcileKeyedTypes();
',
],
];
}