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

Java printer: in a local class, a line comment before a field swallows the field

Aperta
#108 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Start from the round trip described in the issue: parse a local class with a line comment before a field, then run JavaInspector.print2 with Formatter2Impl. Find where the printer emits the comment and the following field for class bodies, and check why local classes take a different path from member classes, which print correctly. Done when the local-class example prints the comment on its own line and the field stays intact and compilable, and the member-class output is unchanged.

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

Descrizione

bug

Problem

In a local class (a class declared inside a method body), a line comment before a field is printed on the same line as the field. The field becomes part of the comment, and the class no longer compiles: every use of the field fails with "cannot find symbol".

int local(List<int[]> in) {
    class Entry {
        public final int a;

        // TODO: a comment before a field
        public final List<int[]> b;

        Entry(int a, List<int[]> b) { this.a = a; this.b = new ArrayList<>(b); }
    }
    return new Entry(1, in).a;
}

prints as

class Entry {
    final int a;
    // TODO: a comment before a field final List<int []> b;
    Entry(int a, List<int []> b) { this.a = a; this.b = new ArrayList<>(b); }
}

The same class declared as a nested (member) class prints correctly, with the comment on its own line.

Expected

A line comment always ends its line, wherever it is.

Seen on

A round trip (parse, then JavaInspector.print2 with Formatter2Impl) on maddi 0.9.5-alpha.5. On real code: fernflower's FinallyProcessor, whose local class BlockStackEntry has // TODO: correct handling (merging) of multiple paths before the field lstStoreVars. Possibly related to #49 (comment positions), but there's no moved code here.

Lingua principale
Java
Stelle
1
Fork
1
Merge medio
2h 51m
PR unite (30g)
3

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.