Parameter closure type extensions for array_map/filter/walk/find + native flavour resolution - #6147
Merged
Merged
Conversation
…ray_walk, array_find Ported from the resolve-type-rewrite-2 branch. The intrinsic blocks in ParametersAcceptorSelector::selectFromArgs() keep providing the same parameter types (and the rule-facing messages), so analysis output does not change - the extensions express the same knowledge through the public FunctionParameterClosureTypeExtension interface. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaBZjgksga4c5s6Q9FniY7
…osure type extensions After a parameter closure type extension overrides the phpdoc-side parameter type, invoke the same extension again on the natively-promoted scope and override the native parameter type too. Extensions asking $scope->getType() then see native types, so the closure parameters keep their native precision without the intrinsic blocks in ParametersAcceptorSelector - verified by neutering the array_map block's native side locally: bug-11014 stays green through the extension path alone. MutatingScope::doNotTreatPhpDocTypesAsCertain() narrows its return type to self (covariant) so the natively-promoted scope can be passed where MutatingScope is expected. The existing PregReplaceCallbackClosureTypeExtension now also resolves the native flavour, making the native side of its match shapes precise (preg_replace_callback_shapes.php). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaBZjgksga4c5s6Q9FniY7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the four
Array*ParameterClosureTypeExtensions from the resolve-type-rewrite-2 branch and teaches the extension hook to resolve the native flavour.Commit 1 adds the extensions verbatim. The intrinsic blocks in
ParametersAcceptorSelector::selectFromArgs()keep providing the same parameter types (and the rule-facing "expects callable(...)" messages come only from them, so they must stay) — analysis output does not change.Commit 2 invokes the matched extension a second time on the natively-promoted scope after a non-null phpdoc-side override, and overrides the native parameter type with the result. Extensions may now see a natively-promoted scope from
$scope->getType(). This keeps closure parameters natively precise without relying on the intrinsic blocks — verified by locally neutering the array_map block's native side:bug-11014.phpstays green through the extension path alone. The existingPregReplaceCallbackClosureTypeExtensionnow also resolves the native flavour, so the native side of its match shapes becomes precise (one expectation upgraded inpreg_replace_callback_shapes.php).Full test suite,
make phpstanandmake csgreen; the only output change is the more precise native match shape.🤖 Generated with Claude Code
https://claude.ai/code/session_01DaBZjgksga4c5s6Q9FniY7