1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 18:48:03 +01:00

Merge branch '4.x' of https://github.com/vimeo/psalm into feature/upgrade-lsp

This commit is contained in:
Andrew Nagy 2022-03-31 18:02:36 +00:00
commit 979ae34268
4 changed files with 39 additions and 38 deletions

View File

@ -3343,8 +3343,8 @@ return [
'ftp_connect' => ['FTP\Connection|false', 'hostname'=>'string', 'port='=>'int', 'timeout='=>'int'], 'ftp_connect' => ['FTP\Connection|false', 'hostname'=>'string', 'port='=>'int', 'timeout='=>'int'],
'ftp_delete' => ['bool', 'ftp'=>'FTP\Connection', 'filename'=>'string'], 'ftp_delete' => ['bool', 'ftp'=>'FTP\Connection', 'filename'=>'string'],
'ftp_exec' => ['bool', 'ftp'=>'FTP\Connection', 'command'=>'string'], 'ftp_exec' => ['bool', 'ftp'=>'FTP\Connection', 'command'=>'string'],
'ftp_fget' => ['bool', 'ftp'=>'FTP\Connection', 'stream'=>'FTP\Connection', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], 'ftp_fget' => ['bool', 'ftp'=>'FTP\Connection', 'stream'=>'resource', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'],
'ftp_fput' => ['bool', 'ftp'=>'FTP\Connection', 'remote_filename'=>'string', 'stream'=>'FTP\Connection', 'mode='=>'int', 'offset='=>'int'], 'ftp_fput' => ['bool', 'ftp'=>'FTP\Connection', 'remote_filename'=>'string', 'stream'=>'resource', 'mode='=>'int', 'offset='=>'int'],
'ftp_get' => ['bool', 'ftp'=>'FTP\Connection', 'local_filename'=>'string', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], 'ftp_get' => ['bool', 'ftp'=>'FTP\Connection', 'local_filename'=>'string', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'],
'ftp_get_option' => ['mixed|false', 'ftp'=>'FTP\Connection', 'option'=>'int'], 'ftp_get_option' => ['mixed|false', 'ftp'=>'FTP\Connection', 'option'=>'int'],
'ftp_login' => ['bool', 'ftp'=>'FTP\Connection', 'username'=>'string', 'password'=>'string'], 'ftp_login' => ['bool', 'ftp'=>'FTP\Connection', 'username'=>'string', 'password'=>'string'],
@ -3352,8 +3352,8 @@ return [
'ftp_mkdir' => ['string|false', 'ftp'=>'FTP\Connection', 'directory'=>'string'], 'ftp_mkdir' => ['string|false', 'ftp'=>'FTP\Connection', 'directory'=>'string'],
'ftp_mlsd' => ['array|false', 'ftp'=>'FTP\Connection', 'directory'=>'string'], 'ftp_mlsd' => ['array|false', 'ftp'=>'FTP\Connection', 'directory'=>'string'],
'ftp_nb_continue' => ['int', 'ftp'=>'FTP\Connection'], 'ftp_nb_continue' => ['int', 'ftp'=>'FTP\Connection'],
'ftp_nb_fget' => ['int', 'ftp'=>'FTP\Connection', 'stream'=>'FTP\Connection', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], 'ftp_nb_fget' => ['int', 'ftp'=>'FTP\Connection', 'stream'=>'resource', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'],
'ftp_nb_fput' => ['int', 'ftp'=>'FTP\Connection', 'remote_filename'=>'string', 'stream'=>'FTP\Connection', 'mode='=>'int', 'offset='=>'int'], 'ftp_nb_fput' => ['int', 'ftp'=>'FTP\Connection', 'remote_filename'=>'string', 'stream'=>'resource', 'mode='=>'int', 'offset='=>'int'],
'ftp_nb_get' => ['int', 'ftp'=>'FTP\Connection', 'local_filename'=>'string', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], 'ftp_nb_get' => ['int', 'ftp'=>'FTP\Connection', 'local_filename'=>'string', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'],
'ftp_nb_put' => ['int', 'ftp'=>'FTP\Connection', 'remote_filename'=>'string', 'local_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], 'ftp_nb_put' => ['int', 'ftp'=>'FTP\Connection', 'remote_filename'=>'string', 'local_filename'=>'string', 'mode='=>'int', 'offset='=>'int'],
'ftp_nlist' => ['array|false', 'ftp'=>'FTP\Connection', 'directory'=>'string'], 'ftp_nlist' => ['array|false', 'ftp'=>'FTP\Connection', 'directory'=>'string'],

View File

@ -135,11 +135,11 @@ return [
], ],
'ftp_fget' => [ 'ftp_fget' => [
'old' => ['bool', 'ftp' => 'resource', 'stream' => 'resource', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], 'old' => ['bool', 'ftp' => 'resource', 'stream' => 'resource', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'],
'new' => ['bool', 'ftp' => 'FTP\Connection', 'stream' => 'FTP\Connection', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], 'new' => ['bool', 'ftp' => 'FTP\Connection', 'stream' => 'resource', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'],
], ],
'ftp_nb_fget' => [ 'ftp_nb_fget' => [
'old' => ['int', 'ftp' => 'resource', 'stream' => 'resource', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], 'old' => ['int', 'ftp' => 'resource', 'stream' => 'resource', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'],
'new' => ['int', 'ftp' => 'FTP\Connection', 'stream' => 'FTP\Connection', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], 'new' => ['int', 'ftp' => 'FTP\Connection', 'stream' => 'resource', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'],
], ],
'ftp_pasv' => [ 'ftp_pasv' => [
'old' => ['bool', 'ftp' => 'resource', 'enable' => 'bool'], 'old' => ['bool', 'ftp' => 'resource', 'enable' => 'bool'],
@ -159,11 +159,11 @@ return [
], ],
'ftp_fput' => [ 'ftp_fput' => [
'old' => ['bool', 'ftp' => 'resource', 'remote_filename' => 'string', 'stream' => 'resource', 'mode=' => 'int', 'offset=' => 'int'], 'old' => ['bool', 'ftp' => 'resource', 'remote_filename' => 'string', 'stream' => 'resource', 'mode=' => 'int', 'offset=' => 'int'],
'new' => ['bool', 'ftp' => 'FTP\Connection', 'remote_filename' => 'string', 'stream' => 'FTP\Connection', 'mode=' => 'int', 'offset=' => 'int'], 'new' => ['bool', 'ftp' => 'FTP\Connection', 'remote_filename' => 'string', 'stream' => 'resource', 'mode=' => 'int', 'offset=' => 'int'],
], ],
'ftp_nb_fput' => [ 'ftp_nb_fput' => [
'old' => ['int', 'ftp' => 'resource', 'remote_filename' => 'string', 'stream' => 'resource', 'mode=' => 'int', 'offset=' => 'int'], 'old' => ['int', 'ftp' => 'resource', 'remote_filename' => 'string', 'stream' => 'resource', 'mode=' => 'int', 'offset=' => 'int'],
'new' => ['int', 'ftp' => 'FTP\Connection', 'remote_filename' => 'string', 'stream' => 'FTP\Connection', 'mode=' => 'int', 'offset=' => 'int'], 'new' => ['int', 'ftp' => 'FTP\Connection', 'remote_filename' => 'string', 'stream' => 'resource', 'mode=' => 'int', 'offset=' => 'int'],
], ],
'ftp_put' => [ 'ftp_put' => [
'old' => ['bool', 'ftp' => 'resource', 'remote_filename' => 'string', 'local_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], 'old' => ['bool', 'ftp' => 'resource', 'remote_filename' => 'string', 'local_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'],

View File

@ -74,6 +74,7 @@ use function array_shift;
use function array_unique; use function array_unique;
use function array_unshift; use function array_unshift;
use function array_values; use function array_values;
use function assert;
use function constant; use function constant;
use function count; use function count;
use function defined; use function defined;
@ -822,38 +823,27 @@ class TypeParser
if (count($generic_params) !== 2) { if (count($generic_params) !== 2) {
throw new TypeParseTreeException('int range must have 2 params'); throw new TypeParseTreeException('int range must have 2 params');
} }
assert(count($parse_tree->children) === 2);
$param0_union_types = array_values($generic_params[0]->getAtomicTypes()); $get_int_range_bound = function (ParseTree $parse_tree, Union $generic_param, string $bound_name): ?int {
$param1_union_types = array_values($generic_params[1]->getAtomicTypes()); if (!$parse_tree instanceof Value
|| count($generic_param->getAtomicTypes()) > 1
if (count($param0_union_types) > 1 || count($param1_union_types) > 1) { || (!$generic_param->getSingleAtomic() instanceof TLiteralInt
throw new TypeParseTreeException('Union types are not allowed in int range type'); && $parse_tree->value !== $bound_name
&& $parse_tree->text !== $bound_name
)
) {
throw new TypeParseTreeException(
"Invalid type \"{$generic_param->getId()}\" as int $bound_name boundary"
);
} }
if (!($param0_union_types[0] instanceof TNamedObject) && !($param0_union_types[0] instanceof TLiteralInt) || $generic_param_atomic = $generic_param->getSingleAtomic();
!($param1_union_types[0] instanceof TNamedObject) && !($param1_union_types[0] instanceof TLiteralInt)) { return $generic_param_atomic instanceof TLiteralInt ? $generic_param_atomic->value : null;
throw new TypeParseTreeException('Unsupported parameter'); };
}
if ($param0_union_types[0] instanceof TNamedObject $min_bound = $get_int_range_bound($parse_tree->children[0], $generic_params[0], TIntRange::BOUND_MIN);
&& $param0_union_types[0]->value !== TIntRange::BOUND_MIN) { $max_bound = $get_int_range_bound($parse_tree->children[1], $generic_params[1], TIntRange::BOUND_MAX);
throw new TypeParseTreeException('Incorrect named object as a min boundary');
}
if ($param1_union_types[0] instanceof TNamedObject
&& $param1_union_types[0]->value !== TIntRange::BOUND_MAX) {
throw new TypeParseTreeException('Incorrect named object as a max boundary');
}
$min_bound = null;
$max_bound = null;
if ($param0_union_types[0] instanceof TLiteralInt) {
$min_bound = $param0_union_types[0]->value;
}
if ($param1_union_types[0] instanceof TLiteralInt) {
$max_bound = $param1_union_types[0]->value;
}
if ($min_bound === null && $max_bound === null) { if ($min_bound === null && $max_bound === null) {
return new TInt(); return new TInt();
@ -865,7 +855,7 @@ class TypeParser
if (is_int($min_bound) && is_int($max_bound) && $min_bound > $max_bound) { if (is_int($min_bound) && is_int($max_bound) && $min_bound > $max_bound) {
throw new TypeParseTreeException( throw new TypeParseTreeException(
"Min bound can't be greater than max bound, int<" . $min_bound . "," . $max_bound . "> given" "Min bound can't be greater than max bound, int<$min_bound, $max_bound> given"
); );
} }

View File

@ -697,6 +697,17 @@ class IntRangeTest extends TestCase
'$_arr===' => 'non-empty-array<int<0, max>, int<0, max>>', '$_arr===' => 'non-empty-array<int<0, max>, int<0, max>>',
], ],
], ],
'minMaxInNamespace' => [
'<?php
namespace Foo {
/**
* @param int<0, max> $_a
* @param int<min, 0> $_b
*/
function bar(int $_a, int $_b): void {}
}
',
]
]; ];
} }