mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Be more rigorous about atomic docblock type reconciliation
This commit is contained in:
parent
6955f77e2e
commit
72675cb5a0
@ -1279,6 +1279,10 @@ class CallChecker
|
||||
|
||||
if ($input_type->getId() === $param_type->getId()) {
|
||||
$input_type->from_docblock = false;
|
||||
|
||||
foreach ($input_type->getTypes() as $atomic_type) {
|
||||
$atomic_type->from_docblock = false;
|
||||
}
|
||||
}
|
||||
|
||||
$context->removeVarFromConflictingClauses($var_id, null, $statements_checker);
|
||||
|
@ -871,7 +871,15 @@ class Reconciler
|
||||
array $suppressed_issues
|
||||
) {
|
||||
$reconciliation = ' and trying to reconcile type \'' . $existing_var_type . '\' to ' . $new_var_type;
|
||||
if ($existing_var_type->from_docblock) {
|
||||
|
||||
$existing_var_atomic_types = $existing_var_type->getTypes();
|
||||
$potential_key = str_replace('!', '', $new_var_type);
|
||||
|
||||
$from_docblock = $existing_var_type->from_docblock
|
||||
|| (isset($existing_var_atomic_types[$potential_key])
|
||||
&& $existing_var_atomic_types[$potential_key]->from_docblock);
|
||||
|
||||
if ($from_docblock) {
|
||||
if (IssueBuffer::accepts(
|
||||
new RedundantConditionGivenDocblockType(
|
||||
'Found a contradiction with a docblock-defined type '
|
||||
|
@ -281,6 +281,28 @@ class RedundantConditionTest extends TestCase
|
||||
'assertions' => [],
|
||||
'error_levels' => ['RedundantConditionGivenDocblockType'],
|
||||
],
|
||||
'isObjectAssertionOnDocblockType' => [
|
||||
'<?php
|
||||
class A {}
|
||||
class B {}
|
||||
|
||||
/** @param A|B $a */
|
||||
function foo($a) : void {
|
||||
if (!is_object($a)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($a instanceof A) {
|
||||
|
||||
} elseif ($a instanceof B) {
|
||||
|
||||
} else {
|
||||
throw new \Exception("bad");
|
||||
}
|
||||
}',
|
||||
'assertions' => [],
|
||||
'error_levels' => ['RedundantConditionGivenDocblockType'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user