Skip to content

Commit

Permalink
Fix crash when redefining method with fewer params (fixes #8141).
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrolGenhald committed Jun 26, 2022
1 parent 9b4c8cb commit e751a27
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1267,15 +1267,17 @@ private function processParams(
$context->hasVariable('$' . $function_param->name);
}

AttributesAnalyzer::analyze(
$this,
$context,
$function_param,
$param_stmts[$offset]->attrGroups,
AttributesAnalyzer::TARGET_PARAMETER
| ($function_param->promoted_property ? AttributesAnalyzer::TARGET_PROPERTY : 0),
$storage->suppressed_issues + $this->getSuppressedIssues()
);
if (count($param_stmts) === count($params)) {
AttributesAnalyzer::analyze(
$this,
$context,
$function_param,
$param_stmts[$offset]->attrGroups,
AttributesAnalyzer::TARGET_PARAMETER
| ($function_param->promoted_property ? AttributesAnalyzer::TARGET_PROPERTY : 0),
$storage->suppressed_issues + $this->getSuppressedIssues()
);
}
}

return $check_stmts;
Expand Down
10 changes: 10 additions & 0 deletions tests/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,16 @@ class Foo {}
class Bar {}
',
],
'dontCrashWhenRedefiningStubbedMethodWithFewerParams' => [
'<?php
if (!class_exists(ArrayObject::class)) {
class ArrayObject
{
public function __construct() {}
}
}
'
],
];
}

Expand Down

0 comments on commit e751a27

Please sign in to comment.