mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +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;
|
||||
|
||||
use Psalm\CodeLocation;
|
||||
use Psalm\Exception\TypeParseTreeException;
|
||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||
use Psalm\Internal\Analyzer\TraitAnalyzer;
|
||||
use Psalm\Internal\Type\Comparator\AtomicTypeComparator;
|
||||
@ -155,29 +156,35 @@ class NegatedAssertionReconciler extends Reconciler
|
||||
return Type::getEmpty();
|
||||
} elseif (substr($assertion, 0, 9) === 'in-array-') {
|
||||
$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(
|
||||
$new_var_type,
|
||||
$existing_var_type,
|
||||
$statements_analyzer->getCodebase()
|
||||
);
|
||||
if ($new_var_type) {
|
||||
$intersection = Type::intersectUnionTypes(
|
||||
$new_var_type,
|
||||
$existing_var_type,
|
||||
$statements_analyzer->getCodebase()
|
||||
);
|
||||
|
||||
if ($intersection === null) {
|
||||
if ($key && $code_location) {
|
||||
self::triggerIssueForImpossible(
|
||||
$existing_var_type,
|
||||
$existing_var_type->getId(),
|
||||
$key,
|
||||
'!' . $assertion,
|
||||
true,
|
||||
$negated,
|
||||
$code_location,
|
||||
$suppressed_issues
|
||||
);
|
||||
if ($intersection === null) {
|
||||
if ($key && $code_location) {
|
||||
self::triggerIssueForImpossible(
|
||||
$existing_var_type,
|
||||
$existing_var_type->getId(),
|
||||
$key,
|
||||
'!' . $assertion,
|
||||
true,
|
||||
$negated,
|
||||
$code_location,
|
||||
$suppressed_issues
|
||||
);
|
||||
}
|
||||
|
||||
$failed_reconciliation = 2;
|
||||
}
|
||||
|
||||
$failed_reconciliation = 2;
|
||||
}
|
||||
|
||||
return $existing_var_type;
|
||||
|
Loading…
x
Reference in New Issue
Block a user