1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Only check param-out when no exception is thrown

This commit is contained in:
Matt Brown 2021-03-27 09:50:15 -04:00
parent 12cd9590c8
commit c64e879178
2 changed files with 23 additions and 1 deletions

View File

@ -479,7 +479,16 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
}
}
$this->examineParamTypes($statements_analyzer, $context, $codebase);
$final_actions = ScopeAnalyzer::getControlActions(
$this->function->getStmts() ?: [],
null,
$codebase->config->exit_functions,
$context->break_types
);
if ($final_actions !== [ScopeAnalyzer::ACTION_END]) {
$this->examineParamTypes($statements_analyzer, $context, $codebase);
}
foreach ($params as $function_param) {
// only complain if there's no type defined by a parent type

View File

@ -157,6 +157,19 @@ class ReferenceConstraintTest extends TestCase
addValue($foo["a"]);'
],
'paramOutArrayDefaultNullWithThrow' => [
'<?php
/**
* @param-out array{errors: int}|null $info
*/
function idnToAsci(?array &$info = null): void {
if (rand(0, 1)) {
$info = null;
}
throw new \UnexpectedValueException();
}'
],
];
}