diff --git a/src/Rules/Variables/ParameterOutAssignedTypeRule.php b/src/Rules/Variables/ParameterOutAssignedTypeRule.php index 30661636fd..e08d953d87 100644 --- a/src/Rules/Variables/ParameterOutAssignedTypeRule.php +++ b/src/Rules/Variables/ParameterOutAssignedTypeRule.php @@ -12,6 +12,7 @@ use PHPStan\Rules\RuleLevelHelper; use PHPStan\Type\ErrorType; use PHPStan\Type\Type; +use PHPStan\Type\TypeUtils; use PHPStan\Type\VerbosityLevel; use function is_string; use function sprintf; @@ -75,6 +76,8 @@ public function processNode(Node $node, Scope $scope): array $outType = $foundParameter->getType(); } + $outType = TypeUtils::resolveLateResolvableTypes($outType); + $typeResult = $this->ruleLevelHelper->findTypeToCheck( $scope, $node->getAssignedExpr(), diff --git a/src/Rules/Variables/ParameterOutExecutionEndTypeRule.php b/src/Rules/Variables/ParameterOutExecutionEndTypeRule.php index 8638f0aae8..bb8865ce33 100644 --- a/src/Rules/Variables/ParameterOutExecutionEndTypeRule.php +++ b/src/Rules/Variables/ParameterOutExecutionEndTypeRule.php @@ -16,6 +16,7 @@ use PHPStan\Rules\RuleLevelHelper; use PHPStan\Type\ErrorType; use PHPStan\Type\Type; +use PHPStan\Type\TypeUtils; use PHPStan\Type\VerbosityLevel; use function sprintf; @@ -81,6 +82,8 @@ private function processSingleParameter( return []; } + $outType = TypeUtils::resolveLateResolvableTypes($outType); + $variableExpr = new Node\Expr\Variable($parameter->getName()); $typeResult = $this->ruleLevelHelper->findTypeToCheck( $scope, diff --git a/tests/PHPStan/Rules/Variables/data/parameter-out-execution-end.php b/tests/PHPStan/Rules/Variables/data/parameter-out-execution-end.php index 5f0a138225..6f55e987cc 100644 --- a/tests/PHPStan/Rules/Variables/data/parameter-out-execution-end.php +++ b/tests/PHPStan/Rules/Variables/data/parameter-out-execution-end.php @@ -83,3 +83,24 @@ function foo2(?string &$p): void { } } + +class Bug10699 +{ + + /** + * @param int $flags + * @param 10|20 $out + * + * @param-out ($flags is 2 ? 20 : 10) $out + */ + function test2(int $flags, int &$out): void + { + if ($flags === 2) { + $out = 20; + return; + } + + + } + +}