summaryrefslogtreecommitdiff
path: root/prism
diff options
context:
space:
mode:
authorUfuk Kayserilioglu <ufuk.kayserilioglu@shopify.com>2023-12-14 00:14:18 +0200
committergit <svn-admin@ruby-lang.org>2023-12-14 18:05:54 +0000
commit01f21d57297f1e6820a6a374ccf9c432c6178038 (patch)
tree465e27d6f169817b49bc1976d444c0a6e8235197 /prism
parentc5e3d6da9cc7199128218711b89df45c8bf7c6f1 (diff)
[ruby/prism] Fix the implementation of the flag on keyword hash nodes
The previous implementation was incorrect since it was just checking for all keys in assoc nodes to be static literals but the actual check is that all keys in assoc nodes must be symbol nodes. This commit fixes that implementation, and, also, aliases the flag to `PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS` so that ruby/ruby can start using the new flag name. I intend to later change the real flag name to `PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS` and remove the alias. https://github.com/ruby/prism/commit/f5099c79ce
Diffstat (limited to 'prism')
-rw-r--r--prism/parser.h6
-rw-r--r--prism/prism.c9
2 files changed, 11 insertions, 4 deletions
diff --git a/prism/parser.h b/prism/parser.h
index 2c58131b19..7f26054f09 100644
--- a/prism/parser.h
+++ b/prism/parser.h
@@ -17,6 +17,12 @@
#include <stdbool.h>
+// TODO: remove this by renaming the original flag
+/**
+ * Temporary alias for the PM_NODE_FLAG_STATIC_KEYS flag.
+ */
+#define PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS PM_KEYWORD_HASH_NODE_FLAGS_STATIC_KEYS
+
/**
* This enum provides various bits that represent different kinds of states that
* the lexer can track. This is used to determine which kind of token to return
diff --git a/prism/prism.c b/prism/prism.c
index 14bd5542fc..65741a3cab 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -3949,7 +3949,7 @@ pm_keyword_hash_node_create(pm_parser_t *parser) {
.base = {
.type = PM_KEYWORD_HASH_NODE,
.location = PM_OPTIONAL_LOCATION_NOT_PROVIDED_VALUE,
- .flags = PM_KEYWORD_HASH_NODE_FLAGS_STATIC_KEYS
+ .flags = PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS
},
.elements = { 0 }
};
@@ -3962,10 +3962,11 @@ 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
+ // If the element being added is not an AssocNode or does not have a symbol key, then
// we want to turn the STATIC_KEYS flag off.
- if (!PM_NODE_TYPE_P(element, PM_ASSOC_NODE) || !PM_NODE_FLAG_P(((pm_assoc_node_t *) element)->key, PM_NODE_FLAG_STATIC_LITERAL)) {
- pm_node_flag_unset((pm_node_t *)hash, PM_KEYWORD_HASH_NODE_FLAGS_STATIC_KEYS);
+ // TODO: Rename the flag to SYMBOL_KEYS instead.
+ if (!PM_NODE_TYPE_P(element, PM_ASSOC_NODE) || !PM_NODE_TYPE_P(((pm_assoc_node_t *) element)->key, PM_SYMBOL_NODE)) {
+ pm_node_flag_unset((pm_node_t *)hash, PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS);
}
pm_node_list_append(&hash->elements, element);