1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix bad subtyping rule

This commit is contained in:
Matt Brown 2021-05-05 00:42:06 -04:00
parent 27ea40eda0
commit ba90267ea7
2 changed files with 25 additions and 1 deletions

View File

@ -358,7 +358,6 @@ class AtomicTypeComparator
if ($allow_interface_equality if ($allow_interface_equality
|| ($input_type_part instanceof TArray || ($input_type_part instanceof TArray
&& !$input_type_part->type_params[1]->isEmpty()) && !$input_type_part->type_params[1]->isEmpty())
|| $input_type_part instanceof TKeyedArray
) { ) {
return true; return true;
} }

View File

@ -2090,6 +2090,31 @@ class FunctionTemplateTest extends TestCase
createProxy(A::class, \'Ns\foo\')->bar();', createProxy(A::class, \'Ns\foo\')->bar();',
'error_message' => 'InvalidArgument' 'error_message' => 'InvalidArgument'
], ],
'preventBadArraySubtyping' => [
'<?php
/**
* @template T as array{a: int}
* @return T
*/
function foo() : array {
$b = ["a" => 123];
return $b;
}',
'error_message' => 'InvalidReturnStatement'
],
'modifyTemplatedShape' => [
'<?php
/**
* @template T as array{a: int}
* @param T $s
* @return T
*/
function foo(array $s) : array {
$s["a"] = 123;
return $s;
}',
'error_message' => 'InvalidReturnStatement'
],
]; ];
} }
} }