1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Allow magic methods named "as"

Fixes #2881
This commit is contained in:
Brown 2020-02-26 13:50:45 -05:00
parent 9163878174
commit f1dbd0863a
2 changed files with 28 additions and 19 deletions

View File

@ -473,28 +473,30 @@ class ParseTree
break;
case 'as':
$current_parent = $current_leaf->parent;
if ($i > 0) {
$current_parent = $current_leaf->parent;
if (!$current_leaf instanceof ParseTree\Value
|| !$current_parent instanceof ParseTree\GenericTree
|| !$next_token
) {
throw new TypeParseTreeException('Unexpected token ' . $type_token[0]);
if (!$current_leaf instanceof ParseTree\Value
|| !$current_parent instanceof ParseTree\GenericTree
|| !$next_token
) {
throw new TypeParseTreeException('Unexpected token ' . $type_token[0]);
}
array_pop($current_parent->children);
$current_leaf = new ParseTree\TemplateAsTree(
$current_leaf->value,
$next_token[0],
$current_parent
);
$current_parent->children[] = $current_leaf;
++$i;
break;
}
array_pop($current_parent->children);
$current_leaf = new ParseTree\TemplateAsTree(
$current_leaf->value,
$next_token[0],
$current_parent
);
$current_parent->children[] = $current_leaf;
++$i;
break;
default:
$new_parent = !$current_leaf instanceof ParseTree\Root ? $current_leaf : null;

View File

@ -576,6 +576,13 @@ class MagicMethodAnnotationTest extends TestCase
return B::make();
}'
],
'validMethodAsAnnotation' => [
'<?php
/**
* @method string as(string $value)
*/
class Foo {}'
],
];
}