Rust printer: equals/hashCode in a closed class hierarchy

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

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java, rust
Ambito
backend, compilers

Direzione di ricerca

Start with RustTypePrinter to trace why hierarchy equals and hashCode methods are reported as unsupported, then inspect RustBodyPrinter.methodCall and RustJdk for the equality call paths described. Reproduce the fernflower (test-oss) failures, especially the Exprent and Statement cases. Done means hierarchy equality and hashing translate correctly, including inherited or identity comparison and reference or nullable operands, and the affected collection operations compile.

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

Descrizione

The Rust printer does not translate equals/hashCode declared in a closed class hierarchy (RustHierarchies). RustTypePrinter skips such methods and reports UNSUPPORTED ("equals or hashCode in a class hierarchy"), so the hierarchy's enum gets no PartialEq/Hash.

Calls then fail in two ways:

  • a.equals(b) on the hierarchy's root type, which declares no equals itself while its members do, resolves to Object.equals. RustJdk maps that to a plain a == &b, which leaves the two operands at different reference or Option levels, and the enum has no PartialEq in any case.
  • Collection operations that need equality (list.remove(o), indexOf, contains, map keys) on hierarchy members fail the same way.

On fernflower (test-oss) this accounts for 44 of the 62 E0277 "can't compare" errors, in 34 functions, mostly Exprent and Statement. For example, if (asexpr.getLeft().equals(field)) becomes asexpr.get_left().as_ref().unwrap() == &field.

Proposed translation:

  • print each member's equals as an implementation method, then impl PartialEq for <Root> that dispatches on the kind to the member's implementation;
  • a member without its own equals inherits the nearest one, or is compared by identity when there is none;
  • the same for hashCode → impl Hash, when the hierarchy is used as a key;
  • route Object.equals with a source receiver type to the source-equality branch of RustBodyPrinter.methodCall, so Shared<T> operands compare through Shared::equals and nullable ones through Option<&T>.

🤖 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.