mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Prevent more broad template types being captured
This commit is contained in:
parent
f062f9bb75
commit
a89892a41f
@ -1007,7 +1007,16 @@ class Union
|
||||
|
||||
$this->had_template = true;
|
||||
|
||||
if ($input_type) {
|
||||
if ($input_type
|
||||
&& ($atomic_type->as->isMixed()
|
||||
|| !$codebase
|
||||
|| TypeAnalyzer::isContainedBy(
|
||||
$codebase,
|
||||
$input_type,
|
||||
$atomic_type->as
|
||||
)
|
||||
)
|
||||
) {
|
||||
$generic_param = clone $input_type;
|
||||
|
||||
if ($this->isNullable() && $generic_param->isNullable() && !$generic_param->isNull()) {
|
||||
|
@ -626,7 +626,7 @@ class FunctionCallTest extends TestCase
|
||||
}
|
||||
}',
|
||||
'assertions' => [],
|
||||
'error_levels' => ['MixedAssignment', 'MixedArgument'],
|
||||
'error_levels' => ['MixedAssignment', 'MixedArgument', 'MixedArgumentTypeCoercion'],
|
||||
],
|
||||
'compact' => [
|
||||
'<?php
|
||||
|
@ -2617,6 +2617,26 @@ class TemplateTest extends TestCase
|
||||
'$c' => 'C',
|
||||
]
|
||||
],
|
||||
'unionClassStringTWithTReturnsObjectWhenCoerced' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template T as object
|
||||
* @param T|class-string<T> $s
|
||||
* @return T
|
||||
*/
|
||||
function bar($s) {
|
||||
if (is_object($s)) {
|
||||
return $s;
|
||||
}
|
||||
|
||||
return new $s();
|
||||
}
|
||||
|
||||
function foo(string $s) : object {
|
||||
/** @psalm-suppress ArgumentTypeCoercion */
|
||||
return bar($s);
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user