mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #2593 - don’t crash with bad @param-out annotation
This commit is contained in:
parent
1b7b71f2ca
commit
2ae85f7c8b
@ -2371,8 +2371,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
foreach ($docblock_info->params_out as $docblock_param_out) {
|
||||
$param_name = substr($docblock_param_out['name'], 1);
|
||||
|
||||
foreach ($storage->params as $i => $param_storage) {
|
||||
if ($param_storage->name === $param_name) {
|
||||
try {
|
||||
$out_type = Type::parseTokens(
|
||||
Type::fixUpLocalType(
|
||||
$docblock_param_out['type'],
|
||||
@ -2383,6 +2382,19 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
null,
|
||||
$this->function_template_types + $class_template_types
|
||||
);
|
||||
} catch (TypeParseTreeException $e) {
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidDocblock(
|
||||
$e->getMessage() . ' in docblock for ' . $cased_function_id,
|
||||
new CodeLocation($this->file_scanner, $stmt, null, true)
|
||||
)
|
||||
)) {
|
||||
}
|
||||
|
||||
$storage->has_docblock_issues = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$out_type->queueClassLikesForScanning(
|
||||
$this->codebase,
|
||||
@ -2390,6 +2402,8 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
$storage->template_types ?: []
|
||||
);
|
||||
|
||||
foreach ($storage->params as $i => $param_storage) {
|
||||
if ($param_storage->name === $param_name) {
|
||||
$storage->param_out_types[$i] = $out_type;
|
||||
}
|
||||
}
|
||||
|
@ -224,6 +224,14 @@ class ReferenceConstraintTest extends TestCase
|
||||
$v = 8;',
|
||||
'error_message' => 'ConflictingReferenceConstraint',
|
||||
],
|
||||
'invalidDocblockForBadAnnotation' => [
|
||||
'<?php
|
||||
/**
|
||||
* @param-out array<a(),bool> $ar
|
||||
*/
|
||||
function foo(array &$ar) : void {}',
|
||||
'error_message' => 'InvalidDocblock',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user