1
0
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:
Matthew Brown 2017-12-18 20:08:45 -05:00
parent 17edb2bbe6
commit ab3b8a0cf2
2 changed files with 19 additions and 0 deletions

View File

@ -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();
}

View File

@ -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',
],
];
}
}