Skip to content

Commit

Permalink
Consider offset for truthy int range
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm committed Dec 5, 2024
1 parent 22ef97b commit 7cf4b1a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ public function specifyTypesInCondition(
$sizeType = IntegerRangeType::createAllGreaterThan($leftType->getValue());
}
} elseif ($leftType instanceof IntegerRangeType) {
$sizeType = $leftType;
$sizeType = $context->true()
? IntegerRangeType::fromInterval($leftType->getMin() + $offset, $leftType->getMax())

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Only numeric types are allowed in +, int|null given on the left side.

Check failure on line 289 in src/Analyser/TypeSpecifier.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Only numeric types are allowed in +, int|null given on the left side.
: $leftType;
}

$specifiedTypes = $this->specifyTypesForCountFuncCall($expr->right, $argType, $sizeType, $context, $scope, $rootExpr);
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/bug-4700.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function(array $array, int $count): void {
if (isset($array['e'])) $a[] = $array['e'];
if (count($a) > $count) {
assertType('int<2, 5>', count($a));
assertType('array{0: mixed~null, 1?: mixed~null, 2?: mixed~null, 3?: mixed~null, 4?: mixed~null}', $a);
assertType('array{0: mixed~null, 1: mixed~null, 2?: mixed~null, 3?: mixed~null, 4?: mixed~null}&list', $a);
} else {
assertType('0', count($a));
assertType('array{}', $a);
Expand Down

0 comments on commit 7cf4b1a

Please sign in to comment.