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:
parent
c7d938bbbe
commit
944b281cbe
@ -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,
|
||||
|
@ -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 {}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user