diff --git a/src/Analyser/Generator/ExprHandler/ScalarFloatHandler.php b/src/Analyser/Generator/ExprHandler/ScalarFloatHandler.php new file mode 100644 index 0000000000..8067e6e249 --- /dev/null +++ b/src/Analyser/Generator/ExprHandler/ScalarFloatHandler.php @@ -0,0 +1,53 @@ + + */ +#[AutowiredService] +final class ScalarFloatHandler implements ExprHandler +{ + + public function supports(Expr $expr): bool + { + return $expr instanceof Float_; + } + + public function analyseExpr( + Stmt $stmt, + Expr $expr, + GeneratorScope $scope, + ExpressionContext $context, + ?callable $alternativeNodeCallback, + ): Generator + { + yield from []; + $type = new ConstantFloatType($expr->value); + return new ExprAnalysisResult( + $type, + $type, + $scope, + hasYield: false, + isAlwaysTerminating: false, + throwPoints: [], + impurePoints: [], + specifiedTruthyTypes: new SpecifiedTypes(), + specifiedFalseyTypes: new SpecifiedTypes(), + specifiedNullTypes: new SpecifiedTypes(), + ); + } + +} diff --git a/tests/PHPStan/Analyser/Generator/data/gnsr.php b/tests/PHPStan/Analyser/Generator/data/gnsr.php index efbda7e0a7..f553e3953d 100644 --- a/tests/PHPStan/Analyser/Generator/data/gnsr.php +++ b/tests/PHPStan/Analyser/Generator/data/gnsr.php @@ -269,6 +269,9 @@ function doCast() { assertType('1.0', (double) $a); assertType('true', (bool) $a); assertType("'1'", (string) $a); + + $f = 1.1; + assertType('1', (int) $f); } /**