Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jul 17, 2024
1 parent bc8af0d commit 165bebd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/Type/ExponentiateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ private static function exponentiateConstantScalar(ConstantScalarType $base, Typ
if ($exponent->getMin() !== null) {
$min = self::pow($base->getValue(), $exponent->getMin());
if ($min === null) {
return null;
return new ErrorType();
}
}
if ($exponent->getMax() !== null) {
$max = self::pow($base->getValue(), $exponent->getMax());
if ($max === null) {
return null;
return new ErrorType();
}
}

Expand All @@ -104,9 +104,8 @@ private static function exponentiateConstantScalar(ConstantScalarType $base, Typ

if ($exponent instanceof ConstantScalarType) {
$result = self::pow($base->getValue(), $exponent->getValue());

if ($result === null) {
return null;
return new ErrorType();
}

if (is_int($result)) {
Expand Down
14 changes: 7 additions & 7 deletions tests/PHPStan/Analyser/nsrt/pow.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ function doFoo(int $intA, int $intB, string $s, bool $bool, $numericS, float $fl
assertType('int', pow($intA, 1));
assertType('int', $intA ** '1');

assertType('*ERROR*', pow($intA, $s));
assertType('*ERROR*', $intA ** $s);
assertType('(float|int)', pow($intA, $s));
assertType('(float|int)', $intA ** $s);

assertType('(float|int)', pow($intA, $bool)); // could be int
assertType('(float|int)', $intA ** $bool); // could be int
Expand Down Expand Up @@ -161,11 +161,11 @@ function doFoo(int $intA, int $intB, string $s, bool $bool, $numericS, float $fl

assertType('NAN', pow(-1,5.5));

assertType('*ERROR*', pow($s, 0));
assertType('*ERROR*', $s ** '0');
assertType('*ERROR*', $s ** false);
assertType('*ERROR*', pow($s, 1));
assertType('*ERROR*', $s ** '1');
assertType('1', pow($s, 0));
assertType('1', $s ** '0');
assertType('1', $s ** false);
assertType('(float|int)', pow($s, 1));
assertType('(float|int)', $s ** '1');
assertType('*ERROR*', $s ** $arr);
assertType('*ERROR*', $s ** []);

Expand Down

0 comments on commit 165bebd

Please sign in to comment.