mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 13:51:54 +01:00
Merge pull request #6311 from weirdan/fix-6309
Prevent failures when parsing in-array assertions
This commit is contained in:
commit
2e7763c314
@ -3,6 +3,7 @@
|
|||||||
namespace Psalm\Internal\Type;
|
namespace Psalm\Internal\Type;
|
||||||
|
|
||||||
use Psalm\CodeLocation;
|
use Psalm\CodeLocation;
|
||||||
|
use Psalm\Exception\TypeParseTreeException;
|
||||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||||
use Psalm\Internal\Analyzer\TraitAnalyzer;
|
use Psalm\Internal\Analyzer\TraitAnalyzer;
|
||||||
use Psalm\Internal\Type\Comparator\AtomicTypeComparator;
|
use Psalm\Internal\Type\Comparator\AtomicTypeComparator;
|
||||||
@ -155,29 +156,35 @@ class NegatedAssertionReconciler extends Reconciler
|
|||||||
return Type::getEmpty();
|
return Type::getEmpty();
|
||||||
} elseif (substr($assertion, 0, 9) === 'in-array-') {
|
} elseif (substr($assertion, 0, 9) === 'in-array-') {
|
||||||
$assertion = substr($assertion, 9);
|
$assertion = substr($assertion, 9);
|
||||||
$new_var_type = Type::parseString($assertion);
|
$new_var_type = null;
|
||||||
|
try {
|
||||||
|
$new_var_type = Type::parseString($assertion);
|
||||||
|
} catch (TypeParseTreeException $e) {
|
||||||
|
}
|
||||||
|
|
||||||
$intersection = Type::intersectUnionTypes(
|
if ($new_var_type) {
|
||||||
$new_var_type,
|
$intersection = Type::intersectUnionTypes(
|
||||||
$existing_var_type,
|
$new_var_type,
|
||||||
$statements_analyzer->getCodebase()
|
$existing_var_type,
|
||||||
);
|
$statements_analyzer->getCodebase()
|
||||||
|
);
|
||||||
|
|
||||||
if ($intersection === null) {
|
if ($intersection === null) {
|
||||||
if ($key && $code_location) {
|
if ($key && $code_location) {
|
||||||
self::triggerIssueForImpossible(
|
self::triggerIssueForImpossible(
|
||||||
$existing_var_type,
|
$existing_var_type,
|
||||||
$existing_var_type->getId(),
|
$existing_var_type->getId(),
|
||||||
$key,
|
$key,
|
||||||
'!' . $assertion,
|
'!' . $assertion,
|
||||||
true,
|
true,
|
||||||
$negated,
|
$negated,
|
||||||
$code_location,
|
$code_location,
|
||||||
$suppressed_issues
|
$suppressed_issues
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$failed_reconciliation = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
$failed_reconciliation = 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $existing_var_type;
|
return $existing_var_type;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user