diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php index e2ca612c8..92d81fc46 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php @@ -866,6 +866,11 @@ class ArrayFetchAnalyzer $found_match = true; break; } + + if ($offset_type_part instanceof Type\Atomic\TPositiveInt) { + $found_match = true; + break; + } } if (!$found_match) { diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index ab7015baf..445adc34c 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -335,6 +335,25 @@ class ArrayAccessTest extends TestCase $this->analyzeFile('somefile.php', new \Psalm\Context()); } + public function testDontWorryWhenUnionedWithPositiveInt(): void + { + \Psalm\Config::getInstance()->ensure_array_int_offsets_exist = true; + + $this->addFile( + 'somefile.php', + ' $a + * @param 0|positive-int $b + */ + function foo(array $a, int $b): void { + echo $a[$b]; + }' + ); + + $this->analyzeFile('somefile.php', new \Psalm\Context()); + } + /** * @return iterable,error_levels?:string[]}> */