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:
parent
27ea40eda0
commit
ba90267ea7
@ -358,7 +358,6 @@ class AtomicTypeComparator
|
||||
if ($allow_interface_equality
|
||||
|| ($input_type_part instanceof TArray
|
||||
&& !$input_type_part->type_params[1]->isEmpty())
|
||||
|| $input_type_part instanceof TKeyedArray
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
@ -2090,6 +2090,31 @@ class FunctionTemplateTest extends TestCase
|
||||
createProxy(A::class, \'Ns\foo\')->bar();',
|
||||
'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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user