1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Unsetting list elements should turn to an array

This commit is contained in:
Brown 2019-10-09 12:49:31 -04:00
parent 54d5a25077
commit e822ec7541
2 changed files with 20 additions and 0 deletions

View File

@ -1270,6 +1270,13 @@ class StatementsAnalyzer extends SourceAnalyzer implements StatementsSource
$root_type->addType(
new Type\Atomic\TMixed()
);
} elseif ($atomic_root_type instanceof Type\Atomic\TList) {
$root_type->addType(
new Type\Atomic\TArray([
Type::getInt(),
$atomic_root_type->type_param
])
);
}
}

View File

@ -953,6 +953,19 @@ class ArrayAccessTest extends TestCase
$array[$a] = "b";',
'error_message' => 'UndefinedGlobalVariable',
],
'unsetListElementShouldChangeToArray' => [
'<?php
/**
* @param list<string> $arr
* @return list<string>
*/
function takesList(array $arr) : array {
unset($arr[0]);
return $arr;
}',
'error_message' => 'LessSpecificReturnStatement',
],
];
}
}