diff options
author | yui-knk <spiketeika@gmail.com> | 2024-01-08 14:03:54 +0900 |
---|---|---|
committer | Yuichiro Kaneko <spiketeika@gmail.com> | 2024-01-08 18:48:24 +0900 |
commit | 41e2d180a3466a8d18c44246144a912adadd9d1a (patch) | |
tree | 480515b9584fcdb48c5edb6bfefb9bbdf755b716 /parse.y | |
parent | 7ffff3e043b081a8c72b8f8c537f17388fd127a9 (diff) |
Do not convert NODE_STR to NODE_LIT when the string is hash key
parse.y converted NODE_STR when the string is hash key like
```
h1 = {"str1" => 1}
m1("str2" => 2)
m2({"str3" => 3})
```
This commit stop the conversion.
`static_literal_node_p` needs to know the node is for hash key or not
for the optimization.
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -6877,10 +6877,6 @@ assocs : assoc assoc : arg_value tASSOC arg_value { /*%%%*/ - if (nd_type_p($1, NODE_STR)) { - nd_set_type($1, NODE_LIT); - RB_OBJ_WRITE(p->ast, &RNODE_LIT($1)->nd_lit, rb_fstring(RNODE_LIT($1)->nd_lit)); - } $$ = list_append(p, NEW_LIST($1, &@$), $3); /*% %*/ /*% ripper: assoc_new!($1, $3) %*/ @@ -14941,6 +14937,7 @@ nd_type_st_key_enable_p(NODE *node) case NODE_FLOAT: case NODE_RATIONAL: case NODE_IMAGINARY: + case NODE_STR: case NODE_LINE: case NODE_FILE: return true; @@ -14955,6 +14952,8 @@ nd_st_key(struct parser_params *p, NODE *node) switch (nd_type(node)) { case NODE_LIT: return RNODE_LIT(node)->nd_lit; + case NODE_STR: + return RNODE_STR(node)->nd_lit; case NODE_INTEGER: case NODE_FLOAT: case NODE_RATIONAL: @@ -14974,6 +14973,8 @@ nd_st_key_val(struct parser_params *p, NODE *node) switch (nd_type(node)) { case NODE_LIT: return RNODE_LIT(node)->nd_lit; + case NODE_STR: + return RNODE_STR(node)->nd_lit; case NODE_INTEGER: return rb_node_integer_literal_val(node); case NODE_FLOAT: |