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,25 +2371,39 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
|||||||
foreach ($docblock_info->params_out as $docblock_param_out) {
|
foreach ($docblock_info->params_out as $docblock_param_out) {
|
||||||
$param_name = substr($docblock_param_out['name'], 1);
|
$param_name = substr($docblock_param_out['name'], 1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$out_type = Type::parseTokens(
|
||||||
|
Type::fixUpLocalType(
|
||||||
|
$docblock_param_out['type'],
|
||||||
|
$this->aliases,
|
||||||
|
$this->function_template_types + $class_template_types,
|
||||||
|
$this->type_aliases
|
||||||
|
),
|
||||||
|
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,
|
||||||
|
$this->file_storage,
|
||||||
|
$storage->template_types ?: []
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($storage->params as $i => $param_storage) {
|
foreach ($storage->params as $i => $param_storage) {
|
||||||
if ($param_storage->name === $param_name) {
|
if ($param_storage->name === $param_name) {
|
||||||
$out_type = Type::parseTokens(
|
|
||||||
Type::fixUpLocalType(
|
|
||||||
$docblock_param_out['type'],
|
|
||||||
$this->aliases,
|
|
||||||
$this->function_template_types + $class_template_types,
|
|
||||||
$this->type_aliases
|
|
||||||
),
|
|
||||||
null,
|
|
||||||
$this->function_template_types + $class_template_types
|
|
||||||
);
|
|
||||||
|
|
||||||
$out_type->queueClassLikesForScanning(
|
|
||||||
$this->codebase,
|
|
||||||
$this->file_storage,
|
|
||||||
$storage->template_types ?: []
|
|
||||||
);
|
|
||||||
|
|
||||||
$storage->param_out_types[$i] = $out_type;
|
$storage->param_out_types[$i] = $out_type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,6 +224,14 @@ class ReferenceConstraintTest extends TestCase
|
|||||||
$v = 8;',
|
$v = 8;',
|
||||||
'error_message' => 'ConflictingReferenceConstraint',
|
'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