Skip to content

Commit e1a61a6

Browse files
authored
Merge branch refs/heads/1.10.x into 1.11.x
2 parents a16184e + 0b6d92d commit e1a61a6

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,13 @@ public function specifyTypesInCondition(
243243
&& $leftType->isInteger()->yes()
244244
) {
245245
if (
246-
$context->truthy() && (IntegerRangeType::createAllGreaterThanOrEqualTo(1 - $offset)->isSuperTypeOf($leftType)->yes())
247-
|| ($context->falsey() && (new ConstantIntegerType(1 - $offset))->isSuperTypeOf($leftType)->yes())
246+
$context->true() && (IntegerRangeType::createAllGreaterThanOrEqualTo(1 - $offset)->isSuperTypeOf($leftType)->yes())
247+
|| ($context->false() && (new ConstantIntegerType(1 - $offset))->isSuperTypeOf($leftType)->yes())
248248
) {
249249
$argType = $scope->getType($expr->right->getArgs()[0]->value);
250250
if ($argType->isArray()->yes()) {
251251
$newType = new NonEmptyArrayType();
252-
if ($context->truthy() && $argType->isList()->yes()) {
252+
if ($context->true() && $argType->isList()->yes()) {
253253
$newType = AccessoryArrayListType::intersectWith($newType);
254254
}
255255

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,7 @@ public function dataFileAsserts(): iterable
14751475
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6613.php');
14761476
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10187.php');
14771477
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10834.php');
1478+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10952.php');
14781479
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10893.php');
14791480
}
14801481

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10952;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
/**
10+
* @return array<int, string>
11+
*/
12+
public function getArray(): array
13+
{
14+
return array_fill(0, random_int(0, 10), 'test');
15+
}
16+
17+
public function test(): void
18+
{
19+
$array = $this->getArray();
20+
21+
if (count($array) > 1) {
22+
assertType('non-empty-array<int, string>', $array);
23+
} else {
24+
assertType('array<int, string>', $array);
25+
}
26+
27+
match (true) {
28+
count($array) > 1 => assertType('non-empty-array<int, string>', $array),
29+
default => assertType('array<int, string>', $array),
30+
};
31+
}
32+
}

0 commit comments

Comments
 (0)