mrb_str_aset_m() should return replace instead of str#6303
Merged
Conversation
`string[]=(idx, replace)` should return `replace`. ## Actual (wrong) ``` string.[]=(idx, replace) → string string.[]=(idx, len, replace) → string ``` ## Expected ``` string.[]=(idx, replace) → replace string.[]=(idx, len, replace) → replace ``` ## Sidenote As of the current mruby-compiler, `(string[idx] = 'X')` creates not only "CALL_NODE" but also "ASGN_NODE" and "OP_MOVE", overriding the wrong return value. On the other hand, `string.[]=(idx, 'X')` creates only "CALL_NODE", exposing the wrong return value. If my new mruby-compiler2, leveraging Prism, took the place of official compiler, `(string[idx] = 'X')` and `string.[]=(idx, 'X')` would be going to generate the same VM code without "OP_MOVE". So I paranoidly added tests. FYI: You can find how the new mruby-compiler2's AST and VM code look like in mruby/c's issue (mruby/c had the same bug): mrubyc/mrubyc#210
Member
|
Merged. But considering the behavior of the current CRuby parser, I assume the Prism generation is a bug. |
Contributor
Author
|
@matz Thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
string[]=(idx, replace)should returnreplace.Actual (wrong)
Expected
Sidenote
As of the current mruby-compiler,
(string[idx] = 'X')creates not only "CALL_NODE" but also "ASGN_NODE" and "OP_MOVE", overriding the wrong return value. On the other hand,string.[]=(idx, 'X')creates only "CALL_NODE", exposing the wrong return value.If my new mruby-compiler2, leveraging Prism, took the place of official compiler,
(string[idx] = 'X')andstring.[]=(idx, 'X')would be going to generate the same VM code without "OP_MOVE". So I paranoidly added tests.FYI: You can find how the new mruby-compiler2's AST and VM code look like in mruby/c's issue (mruby/c had the same bug): mrubyc/mrubyc#210