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:
parent
54d5a25077
commit
e822ec7541
@ -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
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user