mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Keep generic part of shape on array_map return type
Fixes vimeo/psalm#6038
This commit is contained in:
parent
78f3e81b58
commit
6db79be207
@ -187,6 +187,8 @@ class ArrayMapReturnTypeProvider implements \Psalm\Plugin\EventHandler\FunctionR
|
||||
);
|
||||
$atomic_type->is_list = $array_arg_atomic_type->is_list;
|
||||
$atomic_type->sealed = $array_arg_atomic_type->sealed;
|
||||
$atomic_type->previous_key_type = $array_arg_atomic_type->previous_key_type;
|
||||
$atomic_type->previous_value_type = $mapping_return_type;
|
||||
|
||||
return new Type\Union([$atomic_type]);
|
||||
}
|
||||
|
@ -1930,6 +1930,26 @@ class ArrayFunctionCallTest extends TestCase
|
||||
);
|
||||
}'
|
||||
],
|
||||
'arrayMapShapeAndGenericArray' => [
|
||||
'<?php
|
||||
/** @return string[] */
|
||||
function getLine(): array { return ["a", "b"]; }
|
||||
|
||||
$line = getLine();
|
||||
|
||||
if (empty($line[0])) { // converts array<string> to array{0:string}<string>
|
||||
throw new InvalidArgumentException;
|
||||
}
|
||||
|
||||
$line = array_map( // should not destroy <string> part
|
||||
function($val) { return (int)$val; },
|
||||
$line
|
||||
);
|
||||
',
|
||||
'assertions' => [
|
||||
'$line===' => 'array{0: int}<array-key, int>',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user