Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Java printer: arrow-switch case labels print static constants unqualified

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

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

Start with SwitchEntryImpl.print and trace how it chooses qualification for arrow-switch case conditions; compare this with the surrounding qualification used for old-style switch labels. Check the printer tests for switch statements and expressions, then add coverage for a static constant from another class and an enum constant. Done means both arrow-switch forms preserve compilable qualification while enum labels remain valid.

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

Descrizione

bug

SwitchEntryImpl.print prints every case condition with QualificationImpl.SIMPLE_ONLY. That is right for an enum constant (Java requires the simple name there before Java 21), but wrong for a static constant of another type:

class Consts { static final int ONE = 1; }
class User {
    int kind(int v) {
        switch (v) {
            case Consts.ONE -> { return 10; }
            default -> { return 20; }
        }
    }
}

prints as case ONE -> ..., which does not compile in User (no ONE in scope). The same holds for a switch expression, which prints its entries the same way. Old-style switches print their labels with the surrounding qualification and are not affected.

Found when printing a method body into another class: the original text was case CodeConstants.GROUP_JUMP ->, the printed copy case GROUP_JUMP ->.

Suggested fix: use SIMPLE_ONLY only when the condition is a field reference to an enum constant of the selector's enum type, and print the other conditions with the given qualification.

Lingua principale
Java
Stelle
1
Fork
1
Merge medio
1h 34m
PR unite (30g)
7

Preparare l'ambiente

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 CodeLaser/maddi

Tutte le issue di CodeLaser/maddi

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.