Rust printer: equals/hashCode in a closed class hierarchy

オープン
#192 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
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分
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CodeLaser/maddi のほかの issue

CodeLaser/maddi の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。