mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 12:55:26 +01:00
Remove unused in-array assertions
These assertions cannot be parsed, since the `in-array` assertion handler always tries to convert assertions to a type
This commit is contained in:
parent
f2db139b15
commit
2a92db8fad
@ -3,7 +3,6 @@
|
|||||||
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;
|
||||||
@ -158,35 +157,29 @@ class NegatedAssertionReconciler extends Reconciler
|
|||||||
|
|
||||||
if (strpos($assertion, 'in-array-') === 0) {
|
if (strpos($assertion, 'in-array-') === 0) {
|
||||||
$assertion = substr($assertion, 9);
|
$assertion = substr($assertion, 9);
|
||||||
$new_var_type = null;
|
$new_var_type = Type::parseString($assertion);
|
||||||
try {
|
|
||||||
$new_var_type = Type::parseString($assertion);
|
|
||||||
} catch (TypeParseTreeException $e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($new_var_type) {
|
$intersection = Type::intersectUnionTypes(
|
||||||
$intersection = Type::intersectUnionTypes(
|
$new_var_type,
|
||||||
$new_var_type,
|
$existing_var_type,
|
||||||
$existing_var_type,
|
$statements_analyzer->getCodebase()
|
||||||
$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 = Reconciler::RECONCILIATION_EMPTY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $existing_var_type;
|
return $existing_var_type;
|
||||||
|
@ -4,7 +4,6 @@ namespace Psalm\Internal\Type;
|
|||||||
|
|
||||||
use Psalm\CodeLocation;
|
use Psalm\CodeLocation;
|
||||||
use Psalm\Codebase;
|
use Psalm\Codebase;
|
||||||
use Psalm\Exception\TypeParseTreeException;
|
|
||||||
use Psalm\Internal\Codebase\ClassConstantByWildcardResolver;
|
use Psalm\Internal\Codebase\ClassConstantByWildcardResolver;
|
||||||
use Psalm\Internal\Codebase\InternalCallMapHandler;
|
use Psalm\Internal\Codebase\InternalCallMapHandler;
|
||||||
use Psalm\Internal\Type\TypeCombiner;
|
use Psalm\Internal\Type\TypeCombiner;
|
||||||
@ -1563,14 +1562,7 @@ class SimpleAssertionReconciler extends Reconciler
|
|||||||
array $suppressed_issues,
|
array $suppressed_issues,
|
||||||
int &$failed_reconciliation
|
int &$failed_reconciliation
|
||||||
): Union {
|
): Union {
|
||||||
try {
|
$new_var_type = Type::parseString($assertion);
|
||||||
$new_var_type = Type::parseString($assertion);
|
|
||||||
} catch (TypeParseTreeException $e) {
|
|
||||||
// Not all assertions can be parsed as type, it's fine.
|
|
||||||
// One particular case is variable array key (e. g. $arr[$key]), which end up as in-array-$arr assertion
|
|
||||||
|
|
||||||
return $existing_var_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
$intersection = Type::intersectUnionTypes($new_var_type, $existing_var_type, $codebase);
|
$intersection = Type::intersectUnionTypes($new_var_type, $existing_var_type, $codebase);
|
||||||
|
|
||||||
|
@ -415,12 +415,6 @@ class Reconciler
|
|||||||
&& $key_parts[2][0] !== '\''
|
&& $key_parts[2][0] !== '\''
|
||||||
&& !is_numeric($key_parts[2])
|
&& !is_numeric($key_parts[2])
|
||||||
) {
|
) {
|
||||||
if (isset($new_types[$key_parts[2]])) {
|
|
||||||
$new_types[$key_parts[2]][] = ['=in-array-' . $key_parts[0]];
|
|
||||||
} else {
|
|
||||||
$new_types[$key_parts[2]] = [['=in-array-' . $key_parts[0]]];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($key_parts[0][0] === '$') {
|
if ($key_parts[0][0] === '$') {
|
||||||
if (isset($new_types[$key_parts[0]])) {
|
if (isset($new_types[$key_parts[0]])) {
|
||||||
$new_types[$key_parts[0]][] = ['=has-array-key-' . $key_parts[2]];
|
$new_types[$key_parts[0]][] = ['=has-array-key-' . $key_parts[2]];
|
||||||
|
Loading…
Reference in New Issue
Block a user