Skip to content

Commit

Permalink
Improve parsing of psalm-type
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Feb 15, 2024
1 parent a05a3a8 commit fbc51a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1948,11 +1948,8 @@ private static function getTypeAliasesFromCommentLines(
continue;
}

if ($var_line_parts[0] === ' ') {
array_shift($var_line_parts);
}

$type_string = implode('', $var_line_parts);
$type_string = ltrim($type_string, "* \n\r");
try {
$type_string = CommentAnalyzer::splitDocLine($type_string)[0];
} catch (DocblockParseException $e) {
Expand Down
22 changes: 22 additions & 0 deletions tests/AnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,28 @@ function example(string $_x) : void {}',
*/
class A {}',
],
'multipeLineGenericArray2' => [
'code' => '<?php
/**
* @psalm-type TRelAlternate =
* list<
* array{
* href: string,
* lang: string
* }
* >
*/
class A {
/** @return TRelAlternate */
public function ret(): array { return []; }
}
$_ = (new A)->ret();
',
'assertions' => [
'$_===' => 'list<array{href: string, lang: string}>'
],
],
'builtInClassInAShape' => [
'code' => '<?php
/**
Expand Down

0 comments on commit fbc51a0

Please sign in to comment.