From 3d356a179df1c852ca1117df52450bab093b7d1a Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Sat, 2 Mar 2024 23:02:32 +0100 Subject: [PATCH] fix inconsistency with @since annotation in phpstub and allow @since stubbed to override callmap --- .../Reflector/FunctionLikeNodeScanner.php | 17 ++++++++++++----- stubs/CoreGenericFunctions.phpstub | 2 ++ stubs/Reflection.phpstub | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php index a49bf51c051..c5f66fe3d4a 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php @@ -510,7 +510,12 @@ public function start(PhpParser\Node\FunctionLike $stmt, bool $fake_method = fal && $function_id && $storage instanceof FunctionStorage ) { - if (($this->codebase->register_stub_files && !InternalCallMapHandler::hasDelta($function_id)) + if (($this->codebase->register_stub_files + && (!InternalCallMapHandler::hasDelta($function_id) + // if the stub is for a specific PHP version, which is equal or lower than the analyzed version + // as otherwise we would have returned already above + // we also want to use the stub, since it contains the correct types for the current version + || !empty($docblock_info->since_php_major_version))) // if the function is autoloaded we want to register it even if it has a delta, since there's a polyfill || ($this->codebase->register_autoload_files && !$this->codebase->functions->hasStubbedFunction($function_id)) @@ -940,10 +945,12 @@ private function createStorageForFunctionLike( && ($this->codebase->register_stub_files || !$this->codebase->functions->hasStubbedFunction($function_id)) ) { - $this->codebase->functions->addGlobalFunction( - $function_id, - $this->file_storage->functions[$function_id], - ); + if (!$this->codebase->register_stub_files || !InternalCallMapHandler::hasDelta($function_id)) { + $this->codebase->functions->addGlobalFunction( + $function_id, + $this->file_storage->functions[$function_id], + ); + } $storage = $this->storage = $this->file_storage->functions[$function_id]; diff --git a/stubs/CoreGenericFunctions.phpstub b/stubs/CoreGenericFunctions.phpstub index e793b13d22b..fba2741fec9 100644 --- a/stubs/CoreGenericFunctions.phpstub +++ b/stubs/CoreGenericFunctions.phpstub @@ -737,6 +737,8 @@ function join($separator, array $array = []): string } /** + * @since 4.0 + * * @psalm-pure * * @param non-empty-string $separator diff --git a/stubs/Reflection.phpstub b/stubs/Reflection.phpstub index 68bc4ffd094..78b1ecad722 100644 --- a/stubs/Reflection.phpstub +++ b/stubs/Reflection.phpstub @@ -640,8 +640,8 @@ class ReflectionParameter implements Reflector { public function getAttributes(?string $name = null, int $flags = 0): array {} /** - * @since 8.0 - */ + * @since 8.0 + */ public function isPromoted(): bool {} /**