1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #2785 - parse wildcards in variables better

This commit is contained in:
Brown 2020-02-10 15:30:06 -05:00
parent 89a0b101e4
commit 41af71556d
3 changed files with 32 additions and 4 deletions

View File

@ -186,7 +186,7 @@ class DocComment
$docblock = trim($docblock);
$docblock = preg_replace('@^/\*\*@', '', $docblock);
$docblock = preg_replace('@\*/$@', '', $docblock);
$docblock = preg_replace('@\*\*?/$@', '', $docblock);
// Normalize multi-line @specials.
$lines = explode("\n", $docblock);
@ -219,7 +219,7 @@ class DocComment
list($data, $data_offset) = $data_info;
if (strpos($data, '*')) {
$data = rtrim(preg_replace('/[ \t]*\*\s*$/', '', $data));
$data = rtrim(preg_replace('/^[ \t]*\*\s*$/', '', $data));
}
$docblock = str_replace($full_match, '', $docblock);

View File

@ -551,7 +551,7 @@ class ParseTree
&& strtolower($nexter_token[0]) !== 'class')
) {
throw new TypeParseTreeException(
'Invalid class constant'
'Invalid class constant ' . ($nexter_token[0] ?? '<empty>')
);
}

View File

@ -569,7 +569,7 @@ class ConstantTest extends TestCase
}
}'
],
'keyOf' => [
'keyOf' => [
'<?php
class A {
const C = [
@ -658,6 +658,34 @@ class ConstantTest extends TestCase
A::foo(3);
A::foo(A::D_4);',
],
'wildcardVarAndReturn' => [
'<?php
class Numbers {
public const ONE = 1;
public const TWO = 2;
}
class Number {
/**
* @var Numbers::*
*/
private $number;
/**
* @param Numbers::* $number
*/
public function __construct($number) {
$this->number = $number;
}
/**
* @return Numbers::*
*/
public function get(): int {
return $this->number;
}
}'
],
];
}