Rust printer: equals/hashCode in a closed class hierarchy

Đang mở
#192 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, rust
Lĩnh vực
backend, compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Java
Star
1
Fork
1
Merge trung bình
48 phút
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CodeLaser/maddi

Tất cả issue của CodeLaser/maddi

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.