Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix @psalm-scope-this not working with FQCN with leading backslash #9030

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Expand Up @@ -76,6 +76,7 @@
use function get_class;
use function in_array;
use function is_string;
use function ltrim;
use function preg_split;
use function reset;
use function round;
Expand Down Expand Up @@ -793,6 +794,7 @@ private function parseStatementDocblock(

if (isset($comments->tags['psalm-scope-this'])) {
$trimmed = trim(reset($comments->tags['psalm-scope-this']));
$trimmed = ltrim($trimmed, '\\');

if (!$codebase->classExists($trimmed)) {
IssueBuffer::maybeAdd(
Expand Down
7 changes: 7 additions & 0 deletions tests/TypeReconciliation/ScopeTest.php
Expand Up @@ -194,6 +194,13 @@ function a(): ?int {
?>
<h1><?= $this->getMessage() ?></h1>',
],
'psalmScopeThisInTemplateFQCN' => [
'code' => '<?php
$e = new Exception(); // necessary to trick Psalm’s scanner for test
/** @psalm-scope-this \Exception */
?>
<h1><?= $this->getMessage() ?></h1>',
],
'psalmVarThisInTemplate' => [
'code' => '<?php
$e = new Exception(); // necessary to trick Psalm’s scanner for test
Expand Down