mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Apply same rules that Hack uses for bottom types
This commit is contained in:
parent
1d2a0f8b39
commit
e3df0ec5e2
@ -818,6 +818,14 @@ class Union
|
||||
$generic_param = clone $input_type;
|
||||
$generic_param->setFromDocblock();
|
||||
|
||||
if (isset($generic_params[$key][0])) {
|
||||
$generic_param = Type::combineUnionTypes(
|
||||
$generic_params[$key][0],
|
||||
$generic_param,
|
||||
$codebase
|
||||
);
|
||||
}
|
||||
|
||||
$generic_params[$key] = [
|
||||
$generic_param,
|
||||
$atomic_type->defining_class
|
||||
|
@ -2571,6 +2571,38 @@ class TemplateTest extends TestCase
|
||||
);',
|
||||
'error_message' => 'TypeCoercion',
|
||||
],
|
||||
'possiblyInvalidArgumentWithUnionFirstArg' => [
|
||||
'<?php
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param T $a
|
||||
* @param T $b
|
||||
* @return T
|
||||
*/
|
||||
function foo($a, $b) {
|
||||
return rand(0, 1) ? $a : $b;
|
||||
}
|
||||
|
||||
echo foo([], "hello");',
|
||||
'error_message' => 'PossiblyInvalidArgument',
|
||||
],
|
||||
'possiblyInvalidArgumentWithUnionSecondArg' => [
|
||||
'<?php
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param T $a
|
||||
* @param T $b
|
||||
* @return T
|
||||
*/
|
||||
function foo($a, $b) {
|
||||
return rand(0, 1) ? $a : $b;
|
||||
}
|
||||
|
||||
echo foo("hello", []);',
|
||||
'error_message' => 'PossiblyInvalidArgument',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user