Enum proxies drop attributes and doc comments of enum cases (incl. 8.6 #[\Override] on cases)

Chiusa
#794 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #804 di @lisachenko — integrata

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php
Ambito
tooling

Direzione di ricerca

The case declarations are built in src/Proxy/Generator/EnumGenerator.php around lines 166-172, from the case name and value only. Pull request #804 is already open against this issue, so check it before starting. Done means each woven case keeps its attributes and doc comment, which the php81-enum fixtures and a new 8.6 fixture with #[\Override] on a case should show.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug PHP-8.4 PHP-8.5 PHP-8.6

What happens

EnumProxyGenerator re-declares every case in the proxy enum, but only with its name and value. Attributes and doc comments on cases are lost:

enum Level: string implements HasMode   // interface HasMode { const DEFAULT = 'none'; }
{
    #[\Override]                         // 8.6: #[\Override] on constants, enum cases included
    case DEFAULT = 'none';
    #[Label('High priority')]
    case High = 'high';
    public function up(): self { return self::High; }
}
// proxy
case DEFAULT = 'none';
case High = 'high';

(new ReflectionEnumUnitCase(Level::class, 'High'))->getAttributes() is empty on a woven enum. This already happens with user attributes on PHP 8.1+. PHP 8.6 adds #[\Override] on class constants, enum cases included, so cases will carry attributes more often. Dropping #[\Override] doesn't break anything at runtime, but its check no longer runs.

Cause

src/Proxy/Generator/EnumGenerator.php#L166-L172 builds each case from name + value only.

Proposed fix

  • Collect the attribute groups of each case with AttributeGroupsGenerator::fromReflector() (the same path methods use) and its doc comment, then emit both on the EnumCase node.
  • Update the php81-enum* fixtures, and add an 8.6 fixture with #[\Override] on a case.

Note: #[\Override] on class constants of woven classes already works. The constant stays in the trait and is checked against the proxy's parent and interfaces, as the RFC describes.

Part of #789.

Lingua principale
PHP
Stelle
1.7k
Fork
166
Merge medio
1g 1h
PR unite (30g)
43

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di goaop/framework

Tutte le issue di goaop/framework

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.