Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.

fix: correctly convert variable character access to letter_of block#512

Merged
takaokouji merged 2 commits into
developfrom
fix/issue-464
Jan 12, 2026
Merged

fix: correctly convert variable character access to letter_of block#512
takaokouji merged 2 commits into
developfrom
fix/issue-464

Conversation

@takaokouji

Copy link
Copy Markdown

Summary

This PR fixes issue #464 where character access on a regular variable (e.g., $my_variable[0]) was incorrectly converted to a list item block (data_itemoflist) instead of a character access block (operator_letter_of).

Implementation details

  • variables.js: The [] handler for the variable type was overly broad, catching all character access. It has been modified to only return a data_itemoflist block if the receiver is actually a list block (isListBlock). Otherwise, it returns null to allow other handlers to process it.
  • operators.js: The [] handler (which creates operator_letter_of) has been updated to accept the variable type in addition to string and block.

Test coverage

  • Added a new test case to test/unit/lib/ruby-to-blocks-converter/variables.test.js that verifies $variable[0] converts to operator_letter_of.
  • Verified that existing list-related tests (list("$var")[1]) still pass.
  • Total tests passed: 101 (42 in variables.test.js, 59 in operaters.test.js).

Usage examples

Ruby code:

$my_variable[0]

Now correctly converts to:

  • Opcode: operator_letter_of
  • String input: data_variable (pointing to $my_variable)
  • Letter input: 1

Breaking changes

None.

Fixes #464

Co-Authored-By: Gemini noreply@google.com

takaokouji and others added 2 commits January 12, 2026 00:26
- In variables.js, only handle '[]' if the receiver is a list block.
- In operators.js, allow 'variable' type in '[]' handler to convert to 'operator_letter_of'.
- This fixes a bug where $my_variable[0] was incorrectly converted to a list item block.

Fixes #464
Co-Authored-By: Gemini <noreply@google.com>
@takaokouji takaokouji merged commit 6489526 into develop Jan 12, 2026
2 checks passed
@takaokouji takaokouji deleted the fix/issue-464 branch January 12, 2026 05:14
github-actions Bot pushed a commit that referenced this pull request Jan 12, 2026
fix: correctly convert variable character access to letter_of block
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

["bug"] 「変数」ブロックと「~の~番目の文字」ブロックの組み合わせの逆変換

1 participant