mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Allow union of 0|positive-int to bypass PossiblyUndefinedIntArrayOffset error
This commit is contained in:
parent
e89f7e3960
commit
938afc5aea
@ -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) {
|
||||
|
@ -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',
|
||||
'<?php
|
||||
/**
|
||||
* @param list<string> $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<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user