1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

merge revision(s) 1b89b99941: [Backport #17534]

Mark pattern labels as unremoveable

	Peephole optimization doesn't play well with find pattern at
	least. The only case when a pattern matching could have
	unreachable patterns is when we have lasgn/dasgn node, which
	shouldn't happen in real-life.

	Fixes https://bugs.ruby-lang.org/issues/17534
	---
	 compile.c                          |  2 +-
	 test/ruby/test_pattern_matching.rb | 10 ++++++++++
	 2 files changed, 11 insertions(+), 1 deletion(-)
This commit is contained in:
NARUSE, Yui 2021-02-02 17:50:00 +09:00
parent fb6cb226a0
commit 2dc39e2fd4
3 changed files with 12 additions and 2 deletions

View file

@ -6400,11 +6400,11 @@ compile_case3(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const orig_no
int pat_line = nd_line(pattern);
LABEL *next_pat = NEW_LABEL(pat_line);
ADD_INSN (cond_seq, pat_line, dup);
// NOTE: set deconstructed_pos to the current cached value location
// (it's "under" the matchee value, so it's position is 2)
CHECK(iseq_compile_pattern_each(iseq, cond_seq, pattern, l1, next_pat, FALSE, 2));
ADD_LABEL(cond_seq, next_pat);
LABEL_UNREMOVABLE(next_pat);
}
else {
COMPILE_ERROR(ERROR_ARGS "unexpected node");

View file

@ -791,6 +791,16 @@ END
true
end
end
# https://bugs.ruby-lang.org/issues/17534
assert_block do
case [0, 1, 2]
in x
true
in [*, 2, *]
false
end
end
end
def test_hash_pattern

View file

@ -12,7 +12,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 28
#define RUBY_PATCHLEVEL 29
#define RUBY_RELEASE_YEAR 2021
#define RUBY_RELEASE_MONTH 2