Skip to content

Commit

Permalink
Merge pull request #9329 from weirdan/propagate-phantom-classes-to-cl…
Browse files Browse the repository at this point in the history
…osure-context
  • Loading branch information
weirdan committed Feb 18, 2023
2 parents d6c47ae + 4f22c2e commit 18edbeb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Psalm/Internal/Analyzer/ClosureAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public static function analyzeExpression(
}

$use_context->calling_method_id = $context->calling_method_id;
$use_context->phantom_classes = $context->phantom_classes;

$closure_analyzer->analyze($use_context, $statements_analyzer->node_data, $context, false);

Expand Down
23 changes: 23 additions & 0 deletions tests/ClosureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,29 @@ function test($var) : void
echo $var; // $var should be string, instead it\'s considered to be Closure|string.
}',
],
'classExistsInOuterScopeOfArrowFunction' => [
'code' => <<<'PHP'
<?php
if (class_exists(Foo::class)) {
/** @return mixed */
fn() => Foo::bar(23, []);
}
PHP,
'assertions' => [],
'ignored_issues' => [],
'php_version' => '7.4',
],
'classExistsInOuterScopeOfAClosure' => [
'code' => <<<'PHP'
<?php
if (class_exists(Foo::class)) {
/** @return mixed */
function () {
return Foo::bar(23, []);
};
}
PHP,
],
];
}

Expand Down

0 comments on commit 18edbeb

Please sign in to comment.