1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Allow by reference parameters in method docblock (#4873)

This commit is contained in:
Fran Moreno 2020-12-21 18:11:34 +01:00 committed by Daniil Gentili
parent 8b8c6e5a02
commit 7ddec46e76
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 25 additions and 5 deletions

View File

@ -157,10 +157,10 @@ class ParseTreeCreator
$default = ''; $default = '';
if ($current_token[0] === '&') { if ($current_token[0] === '&') {
throw new TypeParseTreeException('Magic args cannot be passed by reference'); $byref = true;
} ++$this->t;
$current_token = $this->t < $this->type_token_count ? $this->type_tokens[$this->t] : null;
if ($current_token[0] === '...') { } elseif ($current_token[0] === '...') {
$variadic = true; $variadic = true;
++$this->t; ++$this->t;
@ -648,7 +648,7 @@ class ParseTreeCreator
$current_parent = $this->current_leaf->parent; $current_parent = $this->current_leaf->parent;
if ($this->current_leaf instanceof ParseTree\MethodTree && $current_parent) { if ($current_parent && $current_parent instanceof ParseTree\MethodTree) {
$this->createMethodParam($this->type_tokens[$this->t], $current_parent); $this->createMethodParam($this->type_tokens[$this->t], $current_parent);
return; return;
} }

View File

@ -204,6 +204,26 @@ class MagicMethodAnnotationTest extends TestCase
$child->setArray(["boo"]); $child->setArray(["boo"]);
$child->setArray(["boo"], 8);', $child->setArray(["boo"], 8);',
], ],
'validAnnotationWithByRefParam' => [
'<?php
class ParentClass {
public function __call(string $name, array $args) {}
}
/**
* @template T
* @method void configure(string $string, array &$arr)
*/
class Child extends ParentClass
{
/** @psalm-param T $t */
public function getChild($t): void {}
}
$child = new Child();
$array = [];
$child->configure("foo", $array);',
],
'validAnnotationWithNonEmptyDefaultArray' => [ 'validAnnotationWithNonEmptyDefaultArray' => [
'<?php '<?php
class ParentClass { class ParentClass {