Rust printer: Statement.getBasichead() printed as 'return self' in both branches

Aperta
#196 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java, rust
Ambito
compilers

Direzione di ricerca

Start with the Rust translation of Statement.getBasichead() in the fernflower reproduction and trace how the Shared<Statement> field first is translated through recursive calls returning &Self. Compare the generated Rust with the Java branches and inspect build_continue_set and is_head_do_statement to understand the impact. Done means the translated else branch preserves the recursive call and the translation report identifies any remaining unsupported behavior.

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

Descrizione

bug front-end:rust

On fernflower (test-oss/fernflower, translated with --translate rust), Statement.getBasichead() is printed with self in both branches:

public BasicBlockStatement getBasichead() {
  if (type == StatementType.BASIC_BLOCK) {
    return (BasicBlockStatement)this;
  }
  else {
    return first.getBasichead();
  }
}
pub fn get_basichead(&self) -> &Self {
    if self.r#type == StatementStatementType::BasicBlock {
        return self;
    } else {
        return self;
    }
}

It compiles, so rustc does not catch it, and the translation report has no message for these lines. The recursion into first is gone. Callers that build continue-sets from it (build_continue_set, is_head_do_statement) inherit the wrong result.

The setting:

  • Statement is the root of a closed hierarchy, and BasicBlockStatement is a member of it.
  • first is Option<crate::jrt::Shared<Statement<'a>>>.

A small reproduction with a plain field, then with a nullable field and a member cast (return (Leaf) this / return first.head()), prints the recursion correctly. So the trigger is probably the Shared handle, or the &Self return through it. It is not the cast.

Found while reviewing the printed bodies against the Java.

🤖 Generated with Claude Code

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

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.