Skip to content

fix(ruby-generator): v1 でリスト操作を list() ラッパー記法で出力する (#839)#842

Merged
takaokouji merged 1 commit into
topic/koshien-epic-738from
topic/autopilot-839
Jun 30, 2026
Merged

fix(ruby-generator): v1 でリスト操作を list() ラッパー記法で出力する (#839)#842
takaokouji merged 1 commit into
topic/koshien-epic-738from
topic/autopilot-839

Conversation

@smalruby3-editor-bot

Copy link
Copy Markdown

Summary

Ruby v1 の生成コードが、リスト要素の読み出しや添字操作を 配列記法 $名前[N](0 始まり) で出力していた。v1 の Ruby→Blocks コンバータは配列記法を拒否するため、Ruby タブ ⇄ コードタブのラウンドトリップが壊れていた(Epic #738 の DoD で発覚)。

例: v1 koshien AI でリスト要素を読むと koshien.move_to($最短経路[1]) が生成され、再変換時に「配列の書き方はルビーバージョン2でのみ使えます」エラーになる。

本 PR でジェネレータをバージョン分岐させ、v1 は list("$名前") ラッパー記法(1 始まり)v2 は従来どおり $名前[0 始まり] を出力するようにした。これは docs/smalruby-language-spec-v1-diff.ja.md に既に記載されている v1 仕様(list("@items")[1])への準拠でもある。

Changes Made

  • src/lib/ruby-generator/data-list.js: renderList() / getVersionedIndex() ヘルパーを追加し、全リスト操作をバージョン分岐:
    • data_addtolist(push)/ data_insertatlist(insert・last・random)/ data_deleteoflist(delete_at・last・random)/ data_deletealloflist(clear)/ data_replaceitemoflist[i]=)/ data_itemoflist[i])/ data_itemnumoflist(index)/ data_lengthoflist(length・empty?)/ data_listcontainsitem(include?)
    • v1 は 1 始まり(ブロックに格納された Scratch インデックスをそのまま)、v2 は従来の 0 始まり変換(getListIndex)。
  • src/lib/ruby-generator/data.js: data_listcontents(裸のリスト参照)も v1 で list("$名前") を出力。
  • ハッシュ / 配列リテラル系の分岐(v2 専用)は不変。

Test Coverage

  • test/unit/lib/ruby-generator/data.test.js: 既存のリスト系テストを v2(配列記法)に明示固定し、新規 v1 list() 記法 describe を追加。
  • test/unit/lib/ruby-roundtrip/extension_koshien_v2.test.js: 本 Issue の再現 — v1 koshien koshien.move_to(list("$最短経路")[2]) のラウンドトリップを追加。
  • test/unit/lib/ruby-roundtrip/variables.test.js / book-compat.test.js / while-and-conditions.test.js: バグを記録していた期待値(配列記法・#363 TODO 含む)を真のラウンドトリップ(list(...) 保持)へ修正。
  • test/unit/helpers/ruby-roundtrip-helper.js: ジェネレータのバージョンをコンバータと既定で揃える(本番と同じく単一バージョン設定。配列記法ジェネレータが偶然バージョン非依存だったために隠れていた v2 テストの取りこぼしを是正)。

ローカル: ruby-generator/ + ruby-to-blocks-converter/ 全ユニット(1764 件)、ruby-roundtrip/ 全(252 件)green。lint / prettier clean。

Acceptance Criteria

  • v1 でリスト要素読み出しが list("$名前")[1始まりindex] で生成される
  • v1 の koshien AI が Ruby タブ → コードタブに変換でき、エラーが出ない(再現テスト追加)
  • v1 の他の添字リスト操作も v1 で再変換可能(配列記法を出さない)
  • v2 は現状($名前[0始まり])のまま
  • test/unit/lib/ruby-roundtrip/ 等にユニットテスト追加(v1/v2 双方)

Related

Closes #839

Epic #738 / #743(Ruby v2 対応)/ #827 / #363(v1 ジェネレータの list() 記法保持 TODO を解消)

🤖 Generated with Claude Code

…rray syntax

v1 generated plain array syntax ($name[N], 0-indexed) for all list element

and indexed operations, but the v1 Ruby->Blocks converter rejects array

syntax. Round-tripping a v1 program (e.g. the koshien AI list read

list("$最短経路")[2]) produced $最短経路[1], which fails to re-convert in v1.

Make data-list.js (and data_listcontents) version-aware: v1 emits the

list("$name") wrapper with 1-indexed access; v2 keeps $name[0-indexed].

Covers push/insert/delete_at/replace/item/index/length/include?/clear/empty?.

Aligns with the documented v1 spec (smalruby-language-spec-v1-diff).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@smalruby3-editor-bot smalruby3-editor-bot Bot added the 🤖 autopilot autopilot(AI)が管理する PR/Issue(AI処理対象) label Jun 30, 2026
@smalruby3-editor-bot

smalruby3-editor-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown
Author

🤖 autopilot status

field value
Status Review
AI Status
HITL Yes
Size small

Linked issue #839. Maintained by autopilot (single writer); do not edit.

@github-actions

Copy link
Copy Markdown

🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/topic/autopilot-839/

@smalruby3-editor-bot

Copy link
Copy Markdown
Author

🤖 autopilot 敵対的レビュー完了

別の批判的レビュアーとして差分を精査しました。修正が必要な欠陥は見つかりませんでした。 人間レビューへ進めます。

検証した観点(すべて OK)

  • 正確性: 10 個のリスト操作すべてがバージョン分岐済み(v1 = list("$名前") ラッパー・1 始まり / v2 = $名前[]・0 始まり据え置き)。renderList() / getVersionedIndex() の分岐は last/random/operator_add 等の既存早期分岐と整合。
  • Issue 再現: koshien move_to(list("$最短経路")[2]) の v1 ラウンドトリップ追加テストが green。
  • 早期 return の安全性: data_listcontents / data_itemoflist@ruby:lvar・hash 分岐は v1/v2 判定より前にあり影響なし。
  • ヘルパー変更の影響範囲: ruby-roundtrip-helper.js のジェネレータ版数をコンバータに揃える変更は妥当(本番と同じ単一版数)。ruby-roundtrip/(214) + ruby-generator/(678) 全テスト green。
  • 監査の網羅性: koshien.jskoshienListArg は既に同型分岐済み。他に Ruby のリスト配列記法を出力する箇所は無し(残りの .push は JS 配列操作)。
  • 規約: prettier clean、PR 変更ファイルの eslint clean、CI 9/9 green。Smalruby 固有ファイル(prettierignore ホワイトリスト)のためマーカー不要。ドキュメント仕様(docs/smalruby-language-spec-v1-diff.ja.md)への準拠でありバグ修正の DoD 例外。

所見(任意・ブロッカーではない)

  • version === '2' ? plain : list(...) の分岐が koshien.js / data-list.js(renderList) / data.js(インライン) の 3 箇所に存在。共通ヘルパー化の余地はあるがモジュール跨ぎの refactor で本 Issue のスコープ外。

@smalruby3-editor-bot smalruby3-editor-bot Bot added the 🙋 HITL 人間の対応待ち(レビュー/判断/マージ) label Jun 30, 2026
@smalruby3-editor-bot smalruby3-editor-bot Bot marked this pull request as ready for review June 30, 2026 11:32
@takaokouji takaokouji changed the base branch from topic/koshien-epic-738 to develop June 30, 2026 11:42
@takaokouji takaokouji changed the base branch from develop to topic/koshien-epic-738 June 30, 2026 11:43
@takaokouji takaokouji force-pushed the topic/autopilot-839 branch from 02b512c to f51b2e1 Compare June 30, 2026 11:47
@takaokouji takaokouji merged commit 59f5d18 into topic/koshien-epic-738 Jun 30, 2026
10 checks passed
@takaokouji takaokouji deleted the topic/autopilot-839 branch June 30, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖 autopilot autopilot(AI)が管理する PR/Issue(AI処理対象) 🙋 HITL 人間の対応待ち(レビュー/判断/マージ)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant