File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
tests/PHPStan/Rules/Arrays/data Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -750,6 +750,13 @@ public function getType(Expr $node): Type
750750 return $ this ->getType ($ node ->getVar ())->unsetOffset ($ this ->getType ($ node ->getDim ()));
751751 }
752752 if ($ node instanceof SetOffsetValueTypeExpr) {
753+ $ var = $ node ->getVar () instanceof OriginalPropertyTypeExpr ? $ node ->getVar ()->getPropertyFetch () : $ node ->getVar ();
754+ if ($ node ->getDim () !== null && $ this ->hasExpressionType (new Expr \ArrayDimFetch ($ var , $ node ->getDim ()))->yes ()) {
755+ return $ this ->getType ($ node ->getVar ())->setExistingOffsetValueType (
756+ $ this ->getType ($ node ->getDim ()),
757+ $ this ->getType ($ node ->getValue ()),
758+ );
759+ }
753760 return $ this ->getType ($ node ->getVar ())->setOffsetValueType (
754761 $ node ->getDim () !== null ? $ this ->getType ($ node ->getDim ()) : null ,
755762 $ this ->getType ($ node ->getValue ()),
Original file line number Diff line number Diff line change @@ -59,3 +59,20 @@ public function foo(): void
5959 $ this ->collection2 [] = 2 ;
6060 }
6161}
62+
63+ class TestList
64+ {
65+
66+ /**
67+ * @var list<int>
68+ */
69+ public array $ list = [];
70+
71+ public function setKnownOffset (int $ offset ): void
72+ {
73+ if (isset ($ this ->list [$ offset ])) {
74+ $ this ->list [$ offset ] = 123 ;
75+ }
76+ }
77+
78+ }
You can’t perform that action at this time.
0 commit comments