diff --git a/src/Psalm/Checker/FunctionChecker.php b/src/Psalm/Checker/FunctionChecker.php index 23cf6e955..0d39ef747 100644 --- a/src/Psalm/Checker/FunctionChecker.php +++ b/src/Psalm/Checker/FunctionChecker.php @@ -770,6 +770,7 @@ class FunctionChecker extends FunctionLikeChecker $stmt = $function_call_arg->value->stmts[0]; if ($first_param->variadic === false + && $first_param->var instanceof PhpParser\Node\Expr\Variable && is_string($first_param->var->name) && $stmt instanceof PhpParser\Node\Stmt\Return_ && $stmt->expr diff --git a/src/Psalm/Visitor/DependencyFinderVisitor.php b/src/Psalm/Visitor/DependencyFinderVisitor.php index 7d2d54d02..81ff8977f 100644 --- a/src/Psalm/Visitor/DependencyFinderVisitor.php +++ b/src/Psalm/Visitor/DependencyFinderVisitor.php @@ -772,6 +772,21 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P /** @var PhpParser\Node\Param $param */ foreach ($stmt->getParams() as $param) { + if ($param->var instanceof PhpParser\Node\Expr\Error) { + if (IssueBuffer::accepts( + new InvalidDocblock( + 'Param' . ((int) $i + 1) . ' of ' . $cased_function_id . ' has invalid syntax', + new CodeLocation($this->file_scanner, $param, null, true) + ) + )) { + $storage->has_visitor_issues = true; + + ++$i; + + continue; + } + } + $param_array = $this->getTranslatedFunctionParam($param); if (isset($existing_params['$' . $param_array->name])) { @@ -783,6 +798,8 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P )) { $storage->has_visitor_issues = true; + ++$i; + continue; } } @@ -794,7 +811,11 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P if (!$param_array->is_optional) { $required_param_count = $i + 1; - if (!$param->variadic && $has_optional_param && is_string($param->var->name)) { + if (!$param->variadic + && $has_optional_param + && $param->var instanceof PhpParser\Node\Expr\Variable + && is_string($param->var->name) + ) { if (IssueBuffer::accepts( new MisplacedRequiredParam( 'Required param $' . $param->var->name . ' should come before any optional params in ' . @@ -1271,7 +1292,7 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P $is_optional = $param->default !== null; - if (!is_string($param->var->name)) { + if ($param->var instanceof PhpParser\Node\Expr\Error || !is_string($param->var->name)) { throw new \UnexpectedValueException('Not expecting param name to be non-string'); }