feat(types): array element covariance into a declared array<Object> parameter#520
Open
chadmandoo wants to merge 1 commit into
Open
Conversation
…arameter A PHP `array` parameter is a bare `array` — PHP does NOT enforce the `@param array<T>` element type at runtime, so the declared element type is a hint, not a hard bound. - `types_compatible` accepts `Array(Mixed)` (a spread literal `[...$list, $x]` or an adaptive local) and an element-compatible array in either covariance direction for a declared `Array(T)` parameter — mirroring the whole-value `(_, Mixed) => true` trust posture, one container level down. - `array_literal_element_type_for_ir` now types a method-call element (`[$this->mk()]`) as `Mixed` instead of the syntactic `Int` fallback. The old fallback stored an object-returning method's result in an `Array(Int)` and int-cast it at the element store (a hard backend error). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
A PHP
arrayparameter is a barearray— PHP does not enforce the@param array<T>element type at runtime, so the declared element type is a hint, not a hard bound. Two cases were rejected:How
types_compatibleacceptsArray(Mixed)(a spread literal or an adaptive local) and an element-compatible array in either covariance direction for a declaredArray(T)param — mirroring the whole-value(_, Mixed) => truetrust posture, one container level down.array_literal_element_type_for_irtypes a method-call element asMixedinstead of the syntacticIntfallback. The old fallback stored an object-returning method's result in anArray(Int)and int-cast it at the element store (a hard backend error).Test
test_array_element_covariance_spread_and_method_call— a fluent builder using both a spread element and a method-call element into an object-element array, byte-parity vs PHP 8.5.🤖 Generated with Claude Code