diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index 6e3d216c61e..d60a888f920 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -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; diff --git a/tests/AttributeTest.php b/tests/AttributeTest.php index 4931a67b435..efffdbad4de 100644 --- a/tests/AttributeTest.php +++ b/tests/AttributeTest.php @@ -391,6 +391,16 @@ class Foo {} class Bar {} ', ], + 'dontCrashWhenRedefiningStubbedMethodWithFewerParams' => [ + '