Skip to content

Commit

Permalink
Merge pull request #8174 from AndrolGenhald/fix-attribute-crash
Browse files Browse the repository at this point in the history
Fix crash when redefining method with fewer params (fixes #8141).
  • Loading branch information
orklah committed Jun 26, 2022
2 parents b3038f0 + e751a27 commit 06dd975
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
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
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 06dd975

Please sign in to comment.