1
0
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:
Matthew Brown 2019-01-19 18:51:18 -05:00
parent 1d2a0f8b39
commit e3df0ec5e2
2 changed files with 40 additions and 0 deletions

View File

@ -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

View File

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