Rust printer: equals/hashCode in a closed class hierarchy

未关闭
#192 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java, rust
领域
backend, compilers

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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

主要语言
Java
星标
1
派生
1
平均合并
48 分钟
30 天内合并 PR
2

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

CodeLaser/maddi 的其他 Issue

查看 CodeLaser/maddi 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。