Skip to content

Commit

Permalink
Improve byref array handling
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Feb 7, 2020
1 parent da541db commit 966336a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,7 @@ protected static function checkFunctionArguments(
return false;
}

if ($arg->value instanceof PhpParser\Node\Expr\Variable) {
continue;
}
continue;
}

$toggled_class_exists = false;
Expand Down Expand Up @@ -819,6 +817,12 @@ private static function handleByRefFunctionArg(
return false;
}
}

if (!$arg->value instanceof PhpParser\Node\Expr\Variable) {
if (ExpressionAnalyzer::analyze($statements_analyzer, $arg->value, $context) === false) {
return false;
}
}
}

/**
Expand Down
21 changes: 21 additions & 0 deletions tests/ArrayAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,27 @@ function foo(array $arr) : void {
echo $arr[3] ?? null;
}',
],
'destructureMixed' => [
'<?php
class S {
protected array $a = [];
protected array $b = [];
protected array $c = [];
/**
* @psalm-suppress MixedAssignment
*/
public function pop(): void {
if (!$this->a) {
return;
}
$popped = array_pop($this->a);
[$this->b, $this->c] = $popped;
}
}'
],
];
}

Expand Down

0 comments on commit 966336a

Please sign in to comment.