Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Dec 1, 2023
1 parent 7e94841 commit edf2d1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
14 changes: 0 additions & 14 deletions src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,20 +272,6 @@ public static function analyze(
array_keys($if_scope->negated_types),
);

$extra_vars_to_update = [];

// if there's an object-like array in there, we also need to update the root array variable
foreach ($vars_to_update as $var_id) {
$bracked_pos = strpos($var_id, '[');
if ($bracked_pos !== false) {
$extra_vars_to_update[] = substr($var_id, 0, $bracked_pos);
}
}

if ($extra_vars_to_update) {
$vars_to_update = array_unique(array_merge($extra_vars_to_update, $vars_to_update));
}

$outer_context->update(
$old_if_context,
$if_context,
Expand Down
13 changes: 13 additions & 0 deletions tests/TypeReconciliation/ArrayKeyExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ function getMethodName(array $data = []): void {
}
',
],
'arrayKeyExistsNoSideEffects' => [
'code' => '<?php
function getMethodName(array $ddata = []): void {
if (\array_key_exists("redirect", $ddata)) {
return;
}
if (random_int(0, 1)) {
$ddata["type"] = "test";
}
/** @psalm-check-type-exact $ddata = array<array-key, mixed> */
}
'
]
'arrayKeyExistsTwice' => [

Check failure on line 72 in tests/TypeReconciliation/ArrayKeyExistsTest.php

View workflow job for this annotation

GitHub Actions / build

ParseError

tests/TypeReconciliation/ArrayKeyExistsTest.php:72:13: ParseError: Syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ']' or ')' on line 72 (see https://psalm.dev/173)
'code' => '<?php
function two(array $a): void {
Expand Down

0 comments on commit edf2d1e

Please sign in to comment.