mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #2819 - improve negated assertions on templates
This commit is contained in:
parent
422bd25f04
commit
fb5a0c39cb
@ -155,6 +155,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler
|
||||
$is_strict_equality,
|
||||
$is_loose_equality,
|
||||
$existing_var_type,
|
||||
$template_type_map,
|
||||
$old_var_type_string,
|
||||
$key,
|
||||
$code_location,
|
||||
|
@ -47,6 +47,7 @@ class NegatedAssertionReconciler extends Reconciler
|
||||
* @param string $assertion
|
||||
* @param bool $is_strict_equality
|
||||
* @param bool $is_loose_equality
|
||||
* @param array<string, array<string, array{Type\Union}>> $template_type_map
|
||||
* @param string $old_var_type_string
|
||||
* @param string|null $key
|
||||
* @param CodeLocation|null $code_location
|
||||
@ -61,6 +62,7 @@ class NegatedAssertionReconciler extends Reconciler
|
||||
$is_strict_equality,
|
||||
$is_loose_equality,
|
||||
Type\Union $existing_var_type,
|
||||
array $template_type_map,
|
||||
$old_var_type_string,
|
||||
$key,
|
||||
$code_location,
|
||||
@ -359,7 +361,7 @@ class NegatedAssertionReconciler extends Reconciler
|
||||
&& ($key !== '$this'
|
||||
|| !($statements_analyzer->getSource()->getSource() instanceof TraitAnalyzer))
|
||||
) {
|
||||
$assertion = Type::parseString($assertion);
|
||||
$assertion = Type::parseString($assertion, null, $template_type_map);
|
||||
|
||||
if ($key
|
||||
&& $code_location
|
||||
|
@ -59,6 +59,14 @@ class TTemplateParamClass extends TClassString
|
||||
return 'class-string<' . $this->param_name . ':' . $this->defining_class . ' as ' . $this->as . '>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAssertionString()
|
||||
{
|
||||
return 'class-string<' . $this->param_name . '>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $namespace
|
||||
* @param array<string> $aliased_classes
|
||||
|
@ -618,7 +618,6 @@ class ClassTemplateTest extends TestCase
|
||||
*/
|
||||
public function bar(Foo $object) : void
|
||||
{
|
||||
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
||||
if ($this->getType() !== get_class($object)) {
|
||||
return;
|
||||
}
|
||||
|
@ -637,6 +637,18 @@ class FunctionClassStringTemplateTest extends TestCase
|
||||
'$b_or_c' => 'B|C',
|
||||
]
|
||||
],
|
||||
'allowComparisonWithoutCrash' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template T as object
|
||||
*
|
||||
* @param T::class $e
|
||||
* @param T::class $expected
|
||||
*/
|
||||
function bar(string $e, string $expected) : void {
|
||||
if ($e !== $expected) {}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user