Skip to content

feat: support super keyword in class methods with module include#326

Merged
takaokouji merged 4 commits intodevelopfrom
feature/super-keyword
Mar 16, 2026
Merged

feat: support super keyword in class methods with module include#326
takaokouji merged 4 commits intodevelopfrom
feature/super-keyword

Conversation

@takaokouji
Copy link

@takaokouji takaokouji commented Mar 16, 2026

Summary

moduleinclude した class で super(args) および引数転送 super を使えるようにする機能を実装。super は「モジュールの同名メソッドを呼び出すシンタックスシュガー」として動作する。

Changes Made

Ruby → Blocks 変換

  • visitSuperNode / visitForwardingSuperNode ハンドラー追加(バリデーション含む)
  • visitClassNode に super 事前スキャン追加:class body の DefNode を走査して SuperNode を検出
  • モジュールメソッドリネーム:_super_methodName_N_ パターンで一意な名前に変更
  • @ruby:module_source:Mod:super_of:func コメントで元のメソッド名を記録

Blocks → Ruby 生成

  • @ruby:super コメント → super(args) 出力
  • @ruby:super:forwarding コメント → super 出力(引数なし)
  • @ruby:module_source:Mod:super_of:func → 元のメソッド名 funcmodule Mod 内に出力

バリデーション

  • v1 ではエラー
  • stage ではエラー(include 不可のため)
  • メソッド外ではエラー
  • 同名メソッドが module にない場合はエラー

テスト

  • 11 unit tests (ruby-to-blocks-converter/super.test.js)
  • 2 round-trip tests (ruby-roundtrip-super.test.js)
  • 2 integration tests (ruby-super.test.js)

Implementation Steps

  • Phase 1: エラーメッセージ定義 + SuperNode バリデーション
  • Phase 2: Ruby → Blocks 変換(super の正常系)
  • Phase 3: Blocks → Ruby 生成(super 出力)
  • Phase 4: ラウンドトリップテスト
  • Phase Final: Integration Tests
  • Phase DoD: CI 完了待ち + ブラウザ確認

Definition of Done

  • ユニットテスト pass
  • Integration テスト pass
  • lint pass
  • CI green
  • ブラウザ確認(Playwright MCP):
    • super(args) を含む Ruby コードをエディタに入力し、エラーなくブロックに変換される
    • super(引数転送)を含む Ruby コードをエディタに入力し、エラーなくブロックに変換される
    • ブロックから Ruby タブに切り替えて、super を含む正しい Ruby コードが再生成される
    • v1 モードで super を入力するとエラーメッセージが表示される
    • stage で super を入力するとエラーメッセージが表示される

コード例

module Mod
  def func(a, b)
    a + b
  end
end

class Sprite1
  include Mod

  def func(a)
    super(a, a)
  end

  when_flag_clicked do
    move(func(5))
  end
end

Closes #325

takaokouji and others added 2 commits March 16, 2026 22:24
Add support for `super(args)` and bare `super` (ForwardingSuperNode) in
class methods that override included module methods. super is syntactic
sugar for calling the same-named method in an included module.

Key changes:
- Ruby→Blocks: visitSuperNode/visitForwardingSuperNode handlers with
  validation (v2-only, sprite-only, method-only, matching module method)
- Module method renaming: _super_methodName_N_ pattern when class
  overrides with super
- Blocks→Ruby: @ruby:super and @ruby:super:forwarding comments generate
  correct super calls; @ruby:module_source:Mod:super_of:func restores
  original method name in module output
- Return value propagation for methods ending with super calls

Closes #325

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link

takaokouji and others added 2 commits March 16, 2026 22:38
When super(args) is the last expression in a method, the generator now
correctly outputs just 'super(args)' as the implicit return instead of
the internal return variable reference. Uses returnCallCache_ to pass
the super call code from procedures_definition to data_setvariableto.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The generator adds a blank line between method end and class end when
the method has no event handlers following it. Adjust the expected
output to match.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@takaokouji takaokouji merged commit 6430bfe into develop Mar 16, 2026
9 checks passed
@takaokouji takaokouji deleted the feature/super-keyword branch March 16, 2026 14:27
github-actions bot pushed a commit that referenced this pull request Mar 16, 2026
…-keyword

feat: support super keyword in class methods with module include
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: support super keyword in class methods with module include

1 participant