Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve type alias and class const on UnionTypeComparator #7288

Merged
merged 1 commit into from Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php
Expand Up @@ -362,7 +362,7 @@ public static function canBeContainedBy(
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;
}
Expand All @@ -371,7 +371,7 @@ public static function canBeContainedBy(
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,
Expand Down Expand Up @@ -411,8 +411,8 @@ public static function canExpressionTypesBeIdentical(
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)) {
Expand Down
30 changes: 30 additions & 0 deletions tests/ConstantTest.php
Expand Up @@ -1200,6 +1200,36 @@ class C {
[],
'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();
',
],
];
}

Expand Down