Skip to content

Commit

Permalink
ParameterOutExecutionEndTypeRule - fix for conditional types
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 13, 2024
1 parent 19497ba commit 27c73f7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Rules/Variables/ParameterOutAssignedTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions src/Rules/Variables/ParameterOutExecutionEndTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -81,6 +82,8 @@ private function processSingleParameter(
return [];
}

$outType = TypeUtils::resolveLateResolvableTypes($outType);

$variableExpr = new Node\Expr\Variable($parameter->getName());
$typeResult = $this->ruleLevelHelper->findTypeToCheck(
$scope,
Expand Down
21 changes: 21 additions & 0 deletions tests/PHPStan/Rules/Variables/data/parameter-out-execution-end.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


}

}

0 comments on commit 27c73f7

Please sign in to comment.