Skip to content

Fix GH-17144: type inference narrowing on ZEND_FETCH_DIM_W#21674

Open
iliaal wants to merge 1 commit intophp:PHP-8.4from
iliaal:fix/gh-17144-fetch-dim-w-narrowing
Open

Fix GH-17144: type inference narrowing on ZEND_FETCH_DIM_W#21674
iliaal wants to merge 1 commit intophp:PHP-8.4from
iliaal:fix/gh-17144-fetch-dim-w-narrowing

Conversation

@iliaal
Copy link
Copy Markdown
Contributor

@iliaal iliaal commented Apr 8, 2026

Summary

FETCH_DIM_W stripped MAY_BE_ARRAY_EMPTY only inside a block guarded by key_type & (MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING). When the key operand's type widened across loop iterations (e.g. from MAY_BE_ARRAY to include scalar types), key_type went from 0 to non-zero, causing the flag to be stripped on the second pass but not the first. This violated monotonicity and triggered the narrowing assertion.

Strips MAY_BE_ARRAY_EMPTY for write opcodes (W, RW, LIST_W) regardless of key_type, since a dimension write makes the array non-empty.

Fixes #17144

FETCH_DIM_W stripped MAY_BE_ARRAY_EMPTY only when key_type had valid
key bits. When the key operand's type widened across loop iterations
(from MAY_BE_ARRAY to include scalar types), key_type transitioned
from 0 to non-zero, causing MAY_BE_ARRAY_EMPTY to be stripped on the
second pass but not the first. This violated monotonicity.

Strip MAY_BE_ARRAY_EMPTY for write opcodes (W, RW, LIST_W) regardless
of key_type, since a dimension write makes the array non-empty.

Closes phpGH-17144
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant