Rust printer: Statement.getBasichead() printed as 'return self' in both branches

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
50/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java, rust
領域
compilers

調査の方向性

Start with the Rust translation of Statement.getBasichead() in the fernflower reproduction and trace how the Shared<Statement> field first is translated through recursive calls returning &Self. Compare the generated Rust with the Java branches and inspect build_continue_set and is_head_do_statement to understand the impact. Done means the translated else branch preserves the recursive call and the translation report identifies any remaining unsupported behavior.

索引モデルが issue の本文から書いたものです。

説明

bug front-end:rust

On fernflower (test-oss/fernflower, translated with --translate rust), Statement.getBasichead() is printed with self in both branches:

public BasicBlockStatement getBasichead() {
  if (type == StatementType.BASIC_BLOCK) {
    return (BasicBlockStatement)this;
  }
  else {
    return first.getBasichead();
  }
}
pub fn get_basichead(&self) -> &Self {
    if self.r#type == StatementStatementType::BasicBlock {
        return self;
    } else {
        return self;
    }
}

It compiles, so rustc does not catch it, and the translation report has no message for these lines. The recursion into first is gone. Callers that build continue-sets from it (build_continue_set, is_head_do_statement) inherit the wrong result.

The setting:

  • Statement is the root of a closed hierarchy, and BasicBlockStatement is a member of it.
  • first is Option<crate::jrt::Shared<Statement<'a>>>.

A small reproduction with a plain field, then with a nullable field and a member cast (return (Leaf) this / return first.head()), prints the recursion correctly. So the trigger is probably the Shared handle, or the &Self return through it. It is not the cast.

Found while reviewing the printed bodies against the Java.

🤖 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 を短くまとめたダイジェスト。