Skip to content

Commit

Permalink
Fix usage of array_push results
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jul 16, 2020
1 parent 262bb9f commit a2dbd31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Expand Up @@ -144,6 +144,10 @@ function ($arg) {

if ($is_push && !$unpacked_args) {
for ($i = 1; $i < count($args); $i++) {
$was_inside_assignment = $context->inside_assignment;

$context->inside_assignment = true;

if (ExpressionAnalyzer::analyze(
$statements_analyzer,
$args[$i]->value,
Expand All @@ -152,6 +156,8 @@ function ($arg) {
return false;
}

$context->inside_assignment = $was_inside_assignment;

$old_node_data = $statements_analyzer->node_data;

$statements_analyzer->node_data = clone $statements_analyzer->node_data;
Expand Down
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php
Expand Up @@ -147,7 +147,7 @@ public static function reconcile(
);
}

if ($assertion === 'null' && !$existing_var_type->isMixed()) {
if ($assertion === 'null' && !$existing_var_type->hasMixed()) {
return self::reconcileNull(
$existing_var_type,
$key,
Expand All @@ -158,7 +158,7 @@ public static function reconcile(
);
}

if ($assertion === 'false' && !$existing_var_type->isMixed()) {
if ($assertion === 'false' && !$existing_var_type->hasMixed()) {
return self::reconcileFalse(
$existing_var_type,
$key,
Expand Down
8 changes: 8 additions & 0 deletions tests/UnusedCodeTest.php
Expand Up @@ -736,6 +736,14 @@ function error2(array $keys, int $key): int
return $nextKey;
}'
],
'arrayPushFunctionCall' => [
'<?php
$a = [];
array_push($a, strlen("hello"));
echo $a[0];'
],
];
}

Expand Down

0 comments on commit a2dbd31

Please sign in to comment.