Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
staabm committed Jul 17, 2024
commit 165bebd741ce941bc446f3aeca16d2280d99e5f7
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