@@ -4317,24 +4317,29 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
43174317 && !$ expr ->dim instanceof Expr \PostInc
43184318 ) {
43194319 $ dimType = $ scope ->getType ($ expr ->dim )->toArrayKey ();
4320- if ($ dimType instanceof ConstantIntegerType || $ dimType instanceof ConstantStringType ) {
4320+ if ($ dimType-> isInteger ()-> yes () || $ dimType-> isString ()-> yes () ) {
43214321 $ exprVarType = $ scope ->getType ($ expr ->var );
43224322 if (!$ exprVarType instanceof MixedType && !$ exprVarType ->isArray ()->no ()) {
43234323 $ types = [
43244324 new ArrayType (new MixedType (), new MixedType ()),
43254325 new ObjectType (ArrayAccess::class),
43264326 new NullType (),
43274327 ];
4328- if ($ dimType instanceof ConstantIntegerType ) {
4328+ if ($ dimType-> isInteger ()-> yes () ) {
43294329 $ types [] = new StringType ();
43304330 }
4331+ $ offsetValueType = TypeCombinator::intersect ($ exprVarType , TypeCombinator::union (...$ types ));
4332+
4333+ if ($ dimType instanceof ConstantIntegerType || $ dimType instanceof ConstantStringType) {
4334+ $ offsetValueType = TypeCombinator::intersect (
4335+ $ offsetValueType ,
4336+ new HasOffsetValueType ($ dimType , $ type ),
4337+ );
4338+ }
43314339
43324340 $ scope = $ scope ->specifyExpressionType (
43334341 $ expr ->var ,
4334- TypeCombinator::intersect (
4335- TypeCombinator::intersect ($ exprVarType , TypeCombinator::union (...$ types )),
4336- new HasOffsetValueType ($ dimType , $ type ),
4337- ),
4342+ $ offsetValueType ,
43384343 $ scope ->getNativeType ($ expr ->var ),
43394344 $ certainty ,
43404345 );
0 commit comments