Skip to content

Commit

Permalink
Merge pull request #10362 from robchett/type_aliases_for_static_state…
Browse files Browse the repository at this point in the history
…ment_vars

Allow type aliases for static variables
  • Loading branch information
orklah committed Nov 13, 2023
2 parents b775d29 + 70075e7 commit 5de8390
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Psalm/Internal/Analyzer/CommentAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ public static function getVarComments(
$var_comments = [];

try {
$file_path = $statements_analyzer->getRootFilePath();
$file_storage_provider = $codebase->file_storage_provider;
$file_storage = $file_storage_provider->get($file_path);

$var_comments = $codebase->config->disable_var_parsing
? []
: self::arrayToDocblocks(
Expand All @@ -440,6 +444,7 @@ public static function getVarComments(
$statements_analyzer->getSource(),
$statements_analyzer->getSource()->getAliases(),
$statements_analyzer->getSource()->getTemplateTypeMap(),
$file_storage->type_aliases,
);
} catch (IncorrectDocblockException $e) {
IssueBuffer::maybeAdd(
Expand Down
15 changes: 15 additions & 0 deletions tests/AnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,21 @@ function getPerson_error(): array {
return json_decode($json, true);
}',
],
'psalmTypeAnnotationForStaticVar' => [
'code' => '<?php
/**
* @psalm-type _Type A::TYPE_*
*/
class A{
const TYPE_A = 1;
const TYPE_B = 2;
public function f(): void {
/** @psalm-var _Type $var*/
static $var;
}
}',
],
'allowDocblockDefinedTKeyedArrayIntoNonEmpty' => [
'code' => '<?php
/** @param non-empty-array $_bar */
Expand Down

0 comments on commit 5de8390

Please sign in to comment.