Skip to content

Commit

Permalink
Merge branch 'byref_closure_use' into fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Nov 29, 2023
2 parents 8299f5d + 3f788ae commit 63a4c9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ public function analyze(

foreach ($byref_uses as $var_id => $_) {
$byref_vars[$var_id] = $ref_context->vars_in_scope[$var_id];
$context->vars_in_scope[$var_id] = $ref_context->vars_in_scope[$var_id];
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/ClosureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ public function providerValidCodeParse(): iterable
$v(true);',
],
'byRefUseVarChangeType' => [
'code' => '<?php
function a(string $arg): int {
$v = function() use (&$arg): void {
if (is_integer($arg)) {
echo $arg;
}
if (random_bytes(1)) {
$arg = 123;
}
};
$v();
$v();
return 0;
}
a("test");',
]
'inferredArg' => [
'code' => '<?php
$bar = ["foo", "bar"];
Expand Down

0 comments on commit 63a4c9a

Please sign in to comment.