Skip to content

fix(compiler): allow re-assigning inferred local object to another class - #95

Open
Tinywan wants to merge 1 commit into
swoole:masterfrom
Tinywan:wip/inferred-object-reassignment-pre-ssa
Open

fix(compiler): allow re-assigning inferred local object to another class#95
Tinywan wants to merge 1 commit into
swoole:masterfrom
Tinywan:wip/inferred-object-reassignment-pre-ssa

Conversation

@Tinywan

@Tinywan Tinywan commented Sep 7, 2026

Copy link
Copy Markdown

A local variable has no type declaration; its class is inferred from the first assignment. Re-assigning an unrelated concrete class in a mutually exclusive branch (e.g. ReflectionFunction in if and ReflectionMethod in else) is valid PHP, but was rejected with "Cannot re-assign typed object".

Route both re-assignment sites through reassignInferredObjectVar(), which widens an inferred local to a generic dynamic object. Parameters, native objects, and explicitly declared object types keep the strict check.

A local variable has no type declaration; its class is inferred from the
first assignment. Re-assigning an unrelated concrete class in a mutually
exclusive branch (e.g. ReflectionFunction in `if` and ReflectionMethod in
`else`) is valid PHP, but was rejected with "Cannot re-assign typed object".

Route both re-assignment sites through reassignInferredObjectVar(), which
widens an inferred local to a generic dynamic object. Parameters, native
objects, and explicitly declared object types keep the strict check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant