Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cache for declared function when available before falling back to stubs #8503

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Psalm/Internal/Codebase/Functions.php
Expand Up @@ -84,8 +84,9 @@ public function getStorage(
$function_id = substr($function_id, 1);
}

$from_stubs = false;
if (isset(self::$stubbed_functions[$function_id])) {
return self::$stubbed_functions[$function_id];
$from_stubs = self::$stubbed_functions[$function_id];
}

$file_storage = null;
Expand Down Expand Up @@ -117,6 +118,10 @@ public function getStorage(
return $this->reflection->getFunctionStorage($function_id);
}

if ($from_stubs) {
return $from_stubs;
}

throw new UnexpectedValueException(
'Expecting non-empty $root_file_path and $checked_file_path'
);
Expand All @@ -135,6 +140,10 @@ public function getStorage(
}
}

if ($from_stubs) {
return $from_stubs;
}

throw new UnexpectedValueException(
'Expecting ' . $function_id . ' to have storage in ' . $checked_file_path
);
Expand All @@ -145,6 +154,10 @@ public function getStorage(
$declaring_file_storage = $this->file_storage_provider->get($declaring_file_path);

if (!isset($declaring_file_storage->functions[$function_id])) {
if ($from_stubs) {
return $from_stubs;
}

throw new UnexpectedValueException(
'Not expecting ' . $function_id . ' to not have storage in ' . $declaring_file_path
);
Expand Down