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
750
750
return $ this ->getType ($ node ->getVar ())->unsetOffset ($ this ->getType ($ node ->getDim ()));
751
751
}
752
752
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
+ }
753
760
return $ this ->getType ($ node ->getVar ())->setOffsetValueType (
754
761
$ node ->getDim () !== null ? $ this ->getType ($ node ->getDim ()) : null ,
755
762
$ this ->getType ($ node ->getValue ()),
Original file line number Diff line number Diff line change @@ -59,3 +59,20 @@ public function foo(): void
59
59
$ this ->collection2 [] = 2 ;
60
60
}
61
61
}
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