Skip to content

Reject #[\Override] on trait-provided methods at compile time (#6440)#6477

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-6440-override-trait-direct
Jun 5, 2026
Merged

Reject #[\Override] on trait-provided methods at compile time (#6440)#6477
PurHur merged 1 commit into
masterfrom
agent/issue-6440-override-trait-direct

Conversation

@PurHur
Copy link
Copy Markdown
Owner

@PurHur PurHur commented Jun 5, 2026

Summary

  • #[\Override] no longer treats trait-composed methods as valid override targets — matches php-src zend_compile.c (parent class + interface chain only).
  • Removed trait lookup from ClassCompileRegistry::hasOverridableMethod() / findOverriddenMethod() and simplified OverrideValidator.
  • Updated compliance + unit tests; direct trait override and trait-alias child override both fail at compile time.

Closes #6440

php-src reference

  • Zend/zend_compile.cZEND_ACC_OVERRIDE validation walks parent class chain only; trait methods are not override targets (PHP 8.3+)

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter OverrideAttributeTest'
# OK (4 tests, 7 assertions)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter "override_trait|override_trait_method|override_trait_alias"'
# OK (6 tests, 6 assertions) — VM + JIT compliance

Issue repro (compile-time fatal, exit 255):

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
cat > /tmp/override_trait_direct.php <<'"'"'PHPEOF'"'"'
<?php
trait T { public function f(): void {} }
class C { use T; #[\Override] public function f(): void {} }
PHPEOF
php bin/vm.php /tmp/override_trait_direct.php; echo exit:$?'
# CompileError: C::f() has #[\Override] attribute, but no matching parent method exists
# exit:255

Made with Cursor

Trait-composed methods are not valid override targets in php-src; only
parent class and interface methods count. Removes trait lookup from
OverrideValidator/ClassCompileRegistry and adds compliance guards.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur PurHur merged commit 24e3786 into master Jun 5, 2026
@PurHur PurHur deleted the agent/issue-6440-override-trait-direct branch June 5, 2026 23:41
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.

Language: #[\Override] on trait method alias must be compile-time fatal (zend_compile.c)

1 participant