@@ -4310,24 +4310,29 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
4310
4310
$ scope = $ this ;
4311
4311
if ($ expr instanceof Expr \ArrayDimFetch && $ expr ->dim !== null ) {
4312
4312
$ dimType = $ scope ->getType ($ expr ->dim )->toArrayKey ();
4313
- if ($ dimType instanceof ConstantIntegerType || $ dimType instanceof ConstantStringType ) {
4313
+ if ($ dimType-> isInteger ()-> yes () || $ dimType-> isString ()-> yes () ) {
4314
4314
$ exprVarType = $ scope ->getType ($ expr ->var );
4315
4315
if (!$ exprVarType instanceof MixedType && !$ exprVarType ->isArray ()->no ()) {
4316
4316
$ types = [
4317
4317
new ArrayType (new MixedType (), new MixedType ()),
4318
4318
new ObjectType (ArrayAccess::class),
4319
4319
new NullType (),
4320
4320
];
4321
- if ($ dimType instanceof ConstantIntegerType ) {
4321
+ if ($ dimType-> isInteger ()-> yes () ) {
4322
4322
$ types [] = new StringType ();
4323
4323
}
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
+ }
4324
4332
4325
4333
$ scope = $ scope ->specifyExpressionType (
4326
4334
$ expr ->var ,
4327
- TypeCombinator::intersect (
4328
- TypeCombinator::intersect ($ exprVarType , TypeCombinator::union (...$ types )),
4329
- new HasOffsetValueType ($ dimType , $ type ),
4330
- ),
4335
+ $ offsetValueType ,
4331
4336
$ scope ->getNativeType ($ expr ->var ),
4332
4337
$ certainty ,
4333
4338
);
0 commit comments