diff options
| author | Ufuk Kayserilioglu <ufuk.kayserilioglu@shopify.com> | 2023-12-11 22:26:51 +0200 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-12-12 13:05:09 +0000 |
| commit | 43229d531ff77cd9f8414e75141fcf54fafb22c4 (patch) | |
| tree | 310263600c2c5bd91fc9af159874659c22eaa995 | |
| parent | 25b9a0cbc86da562e765e4fac27bb28311646971 (diff) | |
[ruby/prism] Start `KeywordHashNode`s with `STATIC_KEYS` set, until hit an element that should clear it
https://github.com/ruby/prism/commit/7c7c486507
| -rw-r--r-- | prism/prism.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/prism/prism.c b/prism/prism.c index 9bed7b19d8..1474a1854f 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -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 } }; @@ -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; |
