mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Merge pull request #6739 from orklah/instanceof_notliteral
This commit is contained in:
commit
4b0c8806a7
@ -457,6 +457,9 @@ class AssertionReconciler extends \Psalm\Type\Reconciler
|
||||
if ($key
|
||||
&& $code_location
|
||||
&& $new_type->getId() === $existing_var_type->getId()
|
||||
//even if two objects are the same, equality is not guaranteed
|
||||
// example: (ErrorException and TypeError are both Throwable but not equal)
|
||||
&& !$new_type->hasNamedObjectType()
|
||||
&& !$is_equality
|
||||
&& !($original_assertion === 'loaded-class-string' && $old_var_type_string === 'class-string')
|
||||
&& (!($statements_analyzer->getSource()->getSource() instanceof TraitAnalyzer)
|
||||
|
@ -1102,6 +1102,42 @@ class TypeAlgebraTest extends \Psalm\Tests\TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'ThrowableInstanceOfThrowableMayBeFalse' => [
|
||||
'<?php
|
||||
|
||||
final class Handler
|
||||
{
|
||||
/**
|
||||
* @var class-string<Throwable>[]
|
||||
*/
|
||||
private array $dontReport = [];
|
||||
|
||||
/**
|
||||
* @param class-string<Throwable> $throwable
|
||||
*/
|
||||
public function dontReport(string $throwable): void
|
||||
{
|
||||
$this->dontReport[] = $throwable;
|
||||
}
|
||||
|
||||
public function shouldReport(Throwable $t): bool
|
||||
{
|
||||
foreach ($this->dontReport as $tc) {
|
||||
if ($t instanceof $tc) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$h = new Handler();
|
||||
$h->dontReport(RuntimeException::class);
|
||||
|
||||
$h->shouldReport(new Exception());
|
||||
$h->shouldReport(new RuntimeException());'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user