Skip to content

Commit a74a300

Browse files
committed
numeric-string in array leads to integer key type
1 parent 9c5728d commit a74a300

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Type/ArrayType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public static function castToArrayKeyType(Type $offsetType): Type
296296
return $offsetType;
297297
}
298298

299-
if ($offsetType instanceof FloatType || $offsetType instanceof BooleanType) {
299+
if ($offsetType instanceof FloatType || $offsetType instanceof BooleanType || $offsetType->isNumericString()->yes()) {
300300
return new IntegerType();
301301
}
302302

tests/PHPStan/Analyser/data/bug-3133.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ public function doBaz(
4343
assertType('string&numeric', $numericString);
4444
}
4545

46+
/**
47+
* @param numeric-string $numericString
48+
*/
49+
public function doLorem(
50+
string $numericString
51+
)
52+
{
53+
$a = [];
54+
$a[$numericString] = 'foo';
55+
assertType('array<int, \'foo\'>', $a);
56+
}
57+
4658
}

0 commit comments

Comments
 (0)