@@ -4310,24 +4310,29 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
43104310$ scope = $ this ;
43114311if ($ expr instanceof Expr \ArrayDimFetch && $ expr ->dim !== null ) {
43124312$ dimType = $ scope ->getType ($ expr ->dim )->toArrayKey ();
4313- if ($ dimType instanceof ConstantIntegerType || $ dimType instanceof ConstantStringType ) {
4313+ if ($ dimType-> isInteger ()-> yes () || $ dimType-> isString ()-> yes () ) {
43144314$ exprVarType = $ scope ->getType ($ expr ->var );
43154315if (!$ exprVarType instanceof MixedType && !$ exprVarType ->isArray ()->no ()) {
43164316$ types = [
43174317new ArrayType (new MixedType (), new MixedType ()),
43184318new ObjectType (ArrayAccess::class),
43194319new NullType (),
43204320];
4321- if ($ dimType instanceof ConstantIntegerType ) {
4321+ if ($ dimType-> isInteger ()-> yes () ) {
43224322$ types [] = new StringType ();
43234323}
4324+ $ offsetValueType = TypeCombinator::intersect ($ exprVarType , TypeCombinator::union (...$ types ));
4325+
4326+ if ($ dimType instanceof ConstantIntegerType || $ dimType instanceof ConstantStringType) {
4327+ $ offsetValueType = TypeCombinator::intersect (
4328+ $ offsetValueType ,
4329+ new HasOffsetValueType ($ dimType , $ type ),
4330+ );
4331+ }
43244332
43254333$ scope = $ scope ->specifyExpressionType (
43264334$ expr ->var ,
4327- TypeCombinator::intersect (
4328- TypeCombinator::intersect ($ exprVarType , TypeCombinator::union (...$ types )),
4329- new HasOffsetValueType ($ dimType , $ type ),
4330- ),
4335+ $ offsetValueType ,
43314336$ scope ->getNativeType ($ expr ->var ),
43324337$ certainty ,
43334338);
0 commit comments