Skip to content

Commit 31c71e7

Browse files
committed
More gracefully handle interpolated keys in hpn
1 parent ab47414 commit 31c71e7

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/prism.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16772,15 +16772,23 @@ parse_pattern_hash(pm_parser_t *parser, pm_constant_id_list_t *captures, pm_node
1677216772
case PM_NO_KEYWORDS_PARAMETER_NODE:
1677316773
rest = first_node;
1677416774
break;
16775+
case PM_INTERPOLATED_SYMBOL_NODE:
1677516776
case PM_SYMBOL_NODE: {
1677616777
if (pm_symbol_node_label_p(parser, first_node)) {
16777-
parse_pattern_hash_key(parser, &keys, first_node);
16778+
if (PM_NODE_TYPE_P(first_node, PM_INTERPOLATED_SYMBOL_NODE)) {
16779+
pm_parser_err_node(parser, first_node, PM_ERR_PATTERN_HASH_KEY_INTERPOLATED);
16780+
} else {
16781+
parse_pattern_hash_key(parser, &keys, first_node);
16782+
}
16783+
1677816784
pm_node_t *value;
1677916785

1678016786
if (match8(parser, PM_TOKEN_COMMA, PM_TOKEN_KEYWORD_THEN, PM_TOKEN_BRACE_RIGHT, PM_TOKEN_BRACKET_RIGHT, PM_TOKEN_PARENTHESIS_RIGHT, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON, PM_TOKEN_EOF)) {
16781-
// Otherwise, we will create an implicit local variable
16782-
// target for the value.
16783-
value = parse_pattern_hash_implicit_value(parser, captures, (pm_symbol_node_t *) first_node);
16787+
if (PM_NODE_TYPE_P(first_node, PM_SYMBOL_NODE)) {
16788+
value = parse_pattern_hash_implicit_value(parser, captures, (pm_symbol_node_t *) first_node);
16789+
} else {
16790+
value = UP(pm_error_recovery_node_create(parser, PM_NODE_END(first_node), 0));
16791+
}
1678416792
} else {
1678516793
// Here we have a value for the first assoc in the list, so
1678616794
// we will parse it now.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
case foo; in { "bar#{1}": 1 }; end
2+
^~~~~~~~~~ symbol literal with interpolation is not allowed
3+

0 commit comments

Comments
 (0)