Skip to content
Permalink
Browse files

Check other arguments of array_unshift/array_push

Ref #2052
  • Loading branch information...
muglug committed Aug 26, 2019
1 parent 3e5f6b1 commit 03f59ae05ecaa8942c2cc01faed0225e44bb44f2
Showing with 25 additions and 6 deletions.
  1. +10 −0 src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php
  2. +15 −6 tests/FunctionCallTest.php
@@ -785,6 +785,16 @@ private static function handleArrayAddition(
return false;
}
for ($i = 1; $i < count($args); $i++) {
if (ExpressionAnalyzer::analyze(
$statements_analyzer,
$args[$i]->value,
$context
) === false) {
return false;
}
}
$context->inside_call = true;
if (isset($array_arg->inferredType) && $array_arg->inferredType->hasArray()) {
/** @var TArray|ObjectLike */
@@ -1786,31 +1786,31 @@ function in_array($a, $b) {
'pregMatch' => [
'<?php
function takesInt(int $i) : void {}
takesInt(preg_match("{foo}", "foo"));',
],
'pregMatchWithMatches' => [
'<?php
/** @param string[] $matches */
function takesMatches(array $matches) : void {}
preg_match("{foo}", "foo", $matches);
takesMatches($matches);',
],
'pregMatchWithOffset' => [
'<?php
/** @param string[] $matches */
function takesMatches(array $matches) : void {}
preg_match("{foo}", "foo", $matches, 0, 10);
takesMatches($matches);',
],
'pregMatchWithFlags' => [
'<?php
function takesInt(int $i) : void {}
if (preg_match("{foo}", "this is foo", $matches, PREG_OFFSET_CAPTURE)) {
/**
* @psalm-suppress MixedArrayAccess
@@ -2414,6 +2414,15 @@ function example($x) : void {
}',
'error_message' => 'TypeDoesNotContainType',
],
'arrayShiftUndefinedVariable' => [
'<?php
/** @psalm-suppress MissingParamType */
function foo($data): void {
/** @psalm-suppress MixedArgument */
array_unshift($data, $a);
}',
'error_message' => 'UndefinedVariable',
],
];
}
}

0 comments on commit 03f59ae

Please sign in to comment.
You can’t perform that action at this time.