Skip to content

Commit c4a2e7b

Browse files
Array without 0 is not a list
1 parent 7644bd0 commit c4a2e7b

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/Type/ArrayType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ public function isList(): TrinaryLogic
290290
return TrinaryLogic::createNo();
291291
}
292292

293+
if ($this->getKeyType()->isSuperTypeOf(new ConstantIntegerType(0))->no()) {
294+
return TrinaryLogic::createNo();
295+
}
296+
293297
return TrinaryLogic::createMaybe();
294298
}
295299

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,22 @@ public function testBug9009(): void
32623262
$this->analyse([__DIR__ . '/data/bug-9009.php'], []);
32633263
}
32643264

3265+
public function testBug9487(): void
3266+
{
3267+
$this->checkThisOnly = false;
3268+
$this->checkNullables = false;
3269+
$this->checkUnionTypes = false;
3270+
$this->checkExplicitMixed = false;
3271+
3272+
$this->analyse([__DIR__ . '/data/bug-9487.php'], [
3273+
[
3274+
'Parameter #1 $x of method Bug9487\HelloWorld::sayHello() expects list<string>, array<int<1, max>, string> given.',
3275+
15,
3276+
'array<int<1, max>, string> is not a list.'
3277+
],
3278+
]);
3279+
}
3280+
32653281
public function testBuSplObjectStorageRemove(): void
32663282
{
32673283
$this->checkThisOnly = false;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug9487;
4+
5+
class HelloWorld
6+
{
7+
/** @param list<string> $x */
8+
public function sayHello($x): void
9+
{
10+
}
11+
12+
/** @param array<positive-int, string> $x */
13+
public function invoke($x): void
14+
{
15+
$this->sayHello($x);
16+
}
17+
}

0 commit comments

Comments
 (0)