summaryrefslogtreecommitdiff
path: root/prism_compile.c
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-02-05 12:25:44 -0500
committerKevin Newton <[email protected]>2024-02-05 12:54:52 -0500
commit7eea066cb4830a7b2827fd30bb35d8dcf19ce5f5 (patch)
tree429cb08706e36f2e8f22282e5f34bb168ab431ed /prism_compile.c
parentae7816bc20eefc75be98e5bb3955fe53b932d88f (diff)
[PRISM] Fix pattern matching array with implicit rest
Diffstat (limited to 'prism_compile.c')
-rw-r--r--prism_compile.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/prism_compile.c b/prism_compile.c
index accbd840c1..2ee499b0b7 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -1817,11 +1817,13 @@ pm_compile_pattern(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_node_t
const size_t posts_size = cast->posts.size;
const size_t minimum_size = requireds_size + posts_size;
- bool use_rest_size = (
- cast->rest != NULL &&
- PM_NODE_TYPE_P(cast->rest, PM_SPLAT_NODE) &&
- ((((const pm_splat_node_t *) cast->rest)->expression != NULL) || posts_size > 0)
- );
+ bool rest_named = false;
+ bool use_rest_size = false;
+
+ if (cast->rest != NULL) {
+ rest_named = (PM_NODE_TYPE_P(cast->rest, PM_SPLAT_NODE) && ((const pm_splat_node_t *) cast->rest)->expression != NULL);
+ use_rest_size = (rest_named || (!rest_named && posts_size > 0));
+ }
LABEL *match_failed_label = NEW_LABEL(line.lineno);
LABEL *type_error_label = NEW_LABEL(line.lineno);
@@ -1859,7 +1861,7 @@ pm_compile_pattern(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_node_t
}
if (cast->rest != NULL) {
- if (((const pm_splat_node_t *) cast->rest)->expression != NULL) {
+ if (rest_named) {
ADD_INSN(ret, &line.node, dup);
ADD_INSN1(ret, &line.node, putobject, INT2FIX(requireds_size));
ADD_INSN1(ret, &line.node, topn, INT2FIX(1));