Skip to content
Permalink
Browse files

Fix #2593 - don’t crash with bad @param-out annotation

  • Loading branch information
muglug committed Jan 11, 2020
1 parent 1b7b71f commit 2ae85f7c8bb4436ed0edc1263f93a0f0bc62c69a
Showing with 39 additions and 17 deletions.
  1. +31 −17 src/Psalm/Internal/Visitor/ReflectorVisitor.php
  2. +8 −0 tests/ReferenceConstraintTest.php
@@ -2371,25 +2371,39 @@ function (FunctionLikeParameter $p) {
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) {
$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
);
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)
)
)) {
}

$out_type->queueClassLikesForScanning(
$this->codebase,
$this->file_storage,
$storage->template_types ?: []
);
$storage->has_docblock_issues = true;

continue;
}

$out_type->queueClassLikesForScanning(
$this->codebase,
$this->file_storage,
$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 @@ public function __construct(string &$bar) {
$v = 8;',
'error_message' => 'ConflictingReferenceConstraint',
],
'invalidDocblockForBadAnnotation' => [
'<?php
/**
* @param-out array<a(),bool> $ar
*/
function foo(array &$ar) : void {}',
'error_message' => 'InvalidDocblock',
],
];
}
}

0 comments on commit 2ae85f7

Please sign in to comment.
You can’t perform that action at this time.