Skip to content

Commit 70e8bdb

Browse files
Fix list consideration with union of scalar as offset
1 parent 24bae94 commit 70e8bdb

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Type/Constant/ConstantArrayTypeBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
199199
return;
200200
}
201201

202-
$this->isList = TrinaryLogic::createNo();
203-
204202
$scalarTypes = $offsetType->getConstantScalarTypes();
205203
if (count($scalarTypes) === 0) {
206204
$integerRanges = TypeUtils::getIntegerRanges($offsetType);
@@ -257,6 +255,8 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
257255
return;
258256
}
259257
}
258+
259+
$this->isList = TrinaryLogic::createNo();
260260
}
261261

262262
if ($offsetType === null) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace ArrayIsListUnset;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo {
8+
/**
9+
* @param array{bool, bool, bool} $array
10+
* @param int<0, 1> $key
11+
*/
12+
public function test(array $array, int $key) {
13+
assertType('int<0, 1>', $key);
14+
assertType('true', array_is_list($array));
15+
16+
$array[$key] = false;
17+
assertType('true', array_is_list($array));
18+
}
19+
}

0 commit comments

Comments
 (0)