Rust printer: equals/hashCode in a closed class hierarchy

Abierto
#192 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
java, rust

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Java
Estrellas
1
Forks
1
Merge medio
48 min
PR fusionados (30 d)
2

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de CodeLaser/maddi

Todos los issues de CodeLaser/maddi

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.