@@ -1853,7 +1853,14 @@ private function getTypeFromArrayDimFetch(
18531853 throw new ShouldNotHappenException ();
18541854 }
18551855
1856- if (!$ offsetAccessibleType ->isArray ()->yes () && (new ObjectType (ArrayAccess::class))->isSuperTypeOf ($ offsetAccessibleType )->yes ()) {
1856+ if ($ offsetAccessibleType instanceof NeverType) {
1857+ return $ offsetAccessibleType ;
1858+ }
1859+
1860+ if (
1861+ !$ offsetAccessibleType ->isArray ()->yes ()
1862+ && (new ObjectType (ArrayAccess::class))->isSuperTypeOf ($ offsetAccessibleType )->yes ()
1863+ ) {
18571864 return $ this ->getType (
18581865 new MethodCall (
18591866 $ arrayDimFetch ->var ,
@@ -3364,11 +3371,15 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
33643371 $ dimType = $ scope ->getType ($ expr ->dim )->toArrayKey ();
33653372 if ($ dimType ->isInteger ()->yes () || $ dimType ->isString ()->yes ()) {
33663373 $ exprVarType = $ scope ->getType ($ expr ->var );
3367- if (!$ exprVarType instanceof MixedType && !$ exprVarType ->isArray ()->no ()) {
3368- if ($ dimType ->isInteger ()->yes ()) {
3369- $ varType = TypeCombinator::intersect ($ exprVarType , StaticTypeFactory::intOffsetAccessibleType ());
3370- } else {
3371- $ varType = TypeCombinator::intersect ($ exprVarType , StaticTypeFactory::generalOffsetAccessibleType ());
3374+ $ isArray = $ exprVarType ->isArray ();
3375+ if (!$ exprVarType instanceof MixedType && !$ isArray ->no ()) {
3376+ $ varType = $ exprVarType ;
3377+ if (!$ isArray ->yes ()) {
3378+ if ($ dimType ->isInteger ()->yes ()) {
3379+ $ varType = TypeCombinator::intersect ($ exprVarType , StaticTypeFactory::intOffsetAccessibleType ());
3380+ } else {
3381+ $ varType = TypeCombinator::intersect ($ exprVarType , StaticTypeFactory::generalOffsetAccessibleType ());
3382+ }
33723383 }
33733384
33743385 if ($ dimType instanceof ConstantIntegerType || $ dimType instanceof ConstantStringType) {
0 commit comments