mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Revert "Fix #2724 - make sure behaviour is not dependent on array type"
This reverts commit 1df03b0ff23400b2cbde3140e91fb6b0f8e480ab.
This commit is contained in:
parent
1df03b0ff2
commit
3b6f53a356
@ -117,27 +117,12 @@ class ArrayFetchAnalyzer
|
||||
|
||||
if ($keyed_array_var_id
|
||||
&& $context->hasVariable($keyed_array_var_id)
|
||||
&& !($context->vars_in_scope[$keyed_array_var_id]->possibly_undefined
|
||||
&& ($context->inside_isset || $context->inside_unset))
|
||||
&& !$context->vars_in_scope[$keyed_array_var_id]->possibly_undefined
|
||||
&& !$context->vars_in_scope[$keyed_array_var_id]->isVanillaMixed()
|
||||
) {
|
||||
$stmt_type = $context->vars_in_scope[$keyed_array_var_id];
|
||||
|
||||
if ($stmt_type->possibly_undefined) {
|
||||
if (IssueBuffer::accepts(
|
||||
new PossiblyUndefinedArrayOffset(
|
||||
'Possibly undefined array key ' . $keyed_array_var_id,
|
||||
new CodeLocation($statements_analyzer->getSource(), $stmt)
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
|
||||
$statements_analyzer->node_data->setType(
|
||||
$stmt,
|
||||
clone $stmt_type
|
||||
clone $context->vars_in_scope[$keyed_array_var_id]
|
||||
);
|
||||
|
||||
return;
|
||||
|
@ -226,8 +226,7 @@ class Reconciler
|
||||
$key,
|
||||
$existing_types,
|
||||
$code_location,
|
||||
$has_isset,
|
||||
$has_inverted_isset,
|
||||
$has_isset || $has_inverted_isset,
|
||||
$has_empty
|
||||
);
|
||||
|
||||
@ -433,7 +432,6 @@ class Reconciler
|
||||
array &$existing_keys,
|
||||
?CodeLocation $code_location,
|
||||
bool $has_isset,
|
||||
bool $has_inverted_isset,
|
||||
bool $has_empty
|
||||
) {
|
||||
$key_parts = self::breakUpPathIntoParts($key);
|
||||
@ -490,11 +488,7 @@ class Reconciler
|
||||
|
||||
$new_base_type_candidate = clone $existing_key_type_part->type_params[1];
|
||||
|
||||
if ($has_isset || $has_inverted_isset) {
|
||||
if ($has_inverted_isset) {
|
||||
$new_base_type_candidate = Type::getNull();
|
||||
}
|
||||
|
||||
if ($has_isset) {
|
||||
$new_base_type_candidate->possibly_undefined = true;
|
||||
}
|
||||
} elseif ($existing_key_type_part instanceof Type\Atomic\TList) {
|
||||
@ -504,11 +498,7 @@ class Reconciler
|
||||
|
||||
$new_base_type_candidate = clone $existing_key_type_part->type_param;
|
||||
|
||||
if ($has_isset || $has_inverted_isset) {
|
||||
if ($has_inverted_isset) {
|
||||
$new_base_type_candidate = Type::getNull();
|
||||
}
|
||||
|
||||
if ($has_isset) {
|
||||
$new_base_type_candidate->possibly_undefined = true;
|
||||
}
|
||||
} elseif ($existing_key_type_part instanceof Type\Atomic\TNull) {
|
||||
|
@ -796,20 +796,6 @@ class IssetTest extends \Psalm\Tests\TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'issetOnArrayOfArraysReturningString' => [
|
||||
'<?php
|
||||
function foo(int $i) : ?string {
|
||||
/** @var array<array> */
|
||||
$tokens = [];
|
||||
|
||||
if (!isset($tokens[$i]["a"])) {
|
||||
/** @psalm-suppress PossiblyUndefinedArrayOffset */
|
||||
return $tokens[$i]["a"];
|
||||
}
|
||||
|
||||
return "hello";
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -889,50 +875,6 @@ class IssetTest extends \Psalm\Tests\TestCase
|
||||
}',
|
||||
'error_message' => 'TypeDoesNotContainType'
|
||||
],
|
||||
'issetOnArrayOfMixed' => [
|
||||
'<?php
|
||||
/**
|
||||
* @psalm-suppress PossiblyUndefinedStringArrayOffset
|
||||
* @psalm-suppress MixedArrayAccess
|
||||
* @psalm-suppress MixedArgument
|
||||
*/
|
||||
function foo(int $i) : void {
|
||||
/** @var array */
|
||||
$tokens = [];
|
||||
|
||||
if (!isset($tokens[$i]["a"])) {
|
||||
echo $tokens[$i]["b"];
|
||||
}
|
||||
}',
|
||||
'error_message' => 'PossiblyUndefinedArrayOffset',
|
||||
],
|
||||
'issetOnArrayOfArrays' => [
|
||||
'<?php
|
||||
/**
|
||||
* @psalm-suppress MixedArgument
|
||||
*/
|
||||
function foo(int $i) : void {
|
||||
/** @var array<array> */
|
||||
$tokens = [];
|
||||
|
||||
if (!isset($tokens[$i]["a"])) {
|
||||
echo $tokens[$i]["b"];
|
||||
}
|
||||
}',
|
||||
'error_message' => 'PossiblyUndefinedArrayOffset',
|
||||
],
|
||||
'issetOnArrayOfArrayOfStrings' => [
|
||||
'<?php
|
||||
function foo(int $i) : void {
|
||||
/** @var array<int, array<string, string>> */
|
||||
$tokens = [];
|
||||
|
||||
if (!isset($tokens[$i]["a"])) {
|
||||
echo $tokens[$i]["b"];
|
||||
}
|
||||
}',
|
||||
'error_message' => 'PossiblyUndefinedArrayOffset',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user