Skip to content

Fix trait insteadof + qualified as alias dropping winner method (#9903) - #9913

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-9903-trait-insteadof-as
Jun 19, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-9903-trait-insteadof-as

Conversation

@PurHur

@PurHur PurHur commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix regression where combining TA::f insteadof TB with TB::f as g dropped the winner method f from the class
  • Trait-qualified Trait::method as alias now adds an alias without unsetting the merged method under the original name (matches Zend/zend_traits.c)
  • Applied fix in VM (applyTraitUsesWithAdaptations), JIT trait flattening, and compile-time TraitComposedMethodResolver

Closes #9903

php-src reference

  • Zend/zend_compile.c — trait alias/precedence
  • Zend/zend_inheritance.c — trait method composition

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro-maintainer/trait_use_adaptations.php
vendor/bin/phpunit --filter testTraitInsteadofWithTraitQualifiedAlias
vendor/bin/phpunit test/compliance/cases/language/trait_use_adaptations.phpt
'

Output:

AB
OK (1 test, 1 assertion)  # unit test
OK (1 test, 1 assertion)  # compliance phpt

Made with Cursor

Trait-qualified `TB::f as g` must add an alias from the losing trait without
removing the merged winner `f` from `TA::f insteadof TB`. VM, JIT, and compile-time
TraitComposedMethodResolver now only unset merged names for unqualified renames.

Closes #9903.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 49929c0 into master Jun 19, 2026
@PurHur
PurHur deleted the agent/issue-9903-trait-insteadof-as branch June 19, 2026 07:23
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.

Regression: trait use insteadof/as — adapted methods missing at runtime (re-#3238, Zend/zend_compile.c)

1 participant