mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Make array{a:string} a subtype of array<string, string>
cc @weirdan
This commit is contained in:
parent
17edb2bbe6
commit
ab3b8a0cf2
@ -1101,6 +1101,13 @@ class TypeChecker
|
||||
&& ($container_type_part instanceof TArray || $container_type_part instanceof ObjectLike)
|
||||
) {
|
||||
if ($container_type_part instanceof ObjectLike) {
|
||||
if (!$input_type_part instanceof ObjectLike
|
||||
&& !$input_type_part->type_params[0]->isMixed()
|
||||
) {
|
||||
$all_types_contain = false;
|
||||
$type_coerced = true;
|
||||
}
|
||||
|
||||
$container_type_part = $container_type_part->getGenericArrayType();
|
||||
}
|
||||
|
||||
|
@ -580,6 +580,18 @@ class ReturnTypeTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'InvalidReturnStatement',
|
||||
],
|
||||
'complainAboutObjectLikeWhenArrayIsFound' => [
|
||||
'<?php
|
||||
/** @return array{a:string,b:string,c:string} */
|
||||
function foo() : array {
|
||||
$arr = [];
|
||||
foreach (["a", "b"] as $key) {
|
||||
$arr[$key] = "foo";
|
||||
}
|
||||
return $arr;
|
||||
}',
|
||||
'error_message' => 'LessSpecificReturnStatement',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user