aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
diff options
context:
space:
mode:
authorKazuki Tsujimoto <kazuki@callcc.net>2019-09-01 16:39:34 +0900
committerKazuki Tsujimoto <kazuki@callcc.net>2019-09-01 16:39:34 +0900
commit94d6ec1d90bb28e5f303867b048e6322d8781cb1 (patch)
tree55a794614931f6dc7778f6b1b672ca3a01f0b34f /compile.c
parentcda5745c1bacdb3be8384d21ee0dd70a9d95af5b (diff)
downloadruby-94d6ec1d90bb28e5f303867b048e6322d8781cb1.tar.gz
Make pattern matching support **nil syntax
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/compile.c b/compile.c
index d11e2f9f32..02171c6349 100644
--- a/compile.c
+++ b/compile.c
@@ -5467,7 +5467,15 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c
* end
* end
* if pattern.has_kw_rest_arg_node?
- * pattern.kw_rest_arg_node.match?(d)
+ * if pattern.no_rest_keyword?
+ * unless d.empty?
+ * goto match_failed
+ * end
+ * else
+ * unless pattern.kw_rest_arg_node.match?(d)
+ * goto match_failed
+ * end
+ * end
* end
* true
* goto fin
@@ -5563,9 +5571,16 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c
}
if (node->nd_pkwrestarg) {
- ADD_INSN(ret, line, dup);
- iseq_compile_pattern_each(iseq, ret, node->nd_pkwrestarg, in_alt_pattern);
- ADD_INSNL(ret, line, branchunless, match_failed);
+ if (node->nd_pkwrestarg == NODE_SPECIAL_NO_REST_KEYWORD) {
+ ADD_INSN(ret, line, dup);
+ ADD_SEND(ret, line, idEmptyP, INT2FIX(0));
+ ADD_INSNL(ret, line, branchunless, match_failed);
+ }
+ else {
+ ADD_INSN(ret, line, dup);
+ iseq_compile_pattern_each(iseq, ret, node->nd_pkwrestarg, in_alt_pattern);
+ ADD_INSNL(ret, line, branchunless, match_failed);
+ }
}
ADD_INSN(ret, line, pop);