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

Prevent negation from removing unmatched template vars

This commit is contained in:
Matthew Brown 2022-01-24 13:20:02 -05:00
parent c7d938bbbe
commit 944b281cbe
2 changed files with 21 additions and 1 deletions

View File

@ -30,6 +30,7 @@ use Psalm\Type\Atomic\TLiteralString;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TNonEmptyString;
use Psalm\Type\Atomic\TString;
use Psalm\Type\Atomic\TTemplateParam;
use Psalm\Type\Atomic\TTrue;
use Psalm\Type\Reconciler;
use Psalm\Type\Union;
@ -219,7 +220,8 @@ class NegatedAssertionReconciler extends Reconciler
continue;
}
if (AtomicTypeComparator::isContainedBy(
if (!$existing_var_type_part instanceof TTemplateParam
&& AtomicTypeComparator::isContainedBy(
$codebase,
$existing_var_type_part,
$assertion_type,

View File

@ -3629,6 +3629,24 @@ class ClassTemplateTest extends TestCase
foo($container->get());
'
],
'refineTemplateTypeOfUnion' => [
'code' => '<?php
/** @psalm-template T as One|Two|Three */
class A {
/** @param T $t */
public function __construct(
private object $t
) {}
public function foo(): void {
if ($this->t instanceof One || $this->t instanceof Two) {}
}
}
final class One {}
final class Two {}
final class Three {}',
],
];
}