Skip to content

Commit

Permalink
[ruby/prism] Start KeywordHashNodes with STATIC_KEYS set, until h…
Browse files Browse the repository at this point in the history
…it an element that should clear it

ruby/prism@7c7c486507
  • Loading branch information
paracycle authored and matzbot committed Dec 12, 2023
1 parent 25b9a0c commit 43229d5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion prism/prism.c
Expand Up @@ -3921,7 +3921,8 @@ pm_keyword_hash_node_create(pm_parser_t *parser) {
*node = (pm_keyword_hash_node_t) {
.base = {
.type = PM_KEYWORD_HASH_NODE,
.location = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE
.location = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE,
.flags = PM_KEYWORD_HASH_NODE_FLAGS_STATIC_KEYS
},
.elements = { 0 }
};
Expand All @@ -3934,6 +3935,12 @@ pm_keyword_hash_node_create(pm_parser_t *parser) {
*/
static void
pm_keyword_hash_node_elements_append(pm_keyword_hash_node_t *hash, pm_node_t *element) {
// If the element being added is not an AssocNode or does not have a static literal key, then
// we want to turn the STATIC_KEYS flag off.
if (!PM_NODE_TYPE_P(element, PM_ASSOC_NODE) || (((pm_assoc_node_t *) element)->key->flags & PM_NODE_FLAG_STATIC_LITERAL) == 0) {
hash->base.flags &= (pm_node_flags_t) ~PM_KEYWORD_HASH_NODE_FLAGS_STATIC_KEYS;
}

pm_node_list_append(&hash->elements, element);
if (hash->base.location.start == NULL) {
hash->base.location.start = element->location.start;
Expand Down

0 comments on commit 43229d5

Please sign in to comment.