[前][次][番号順一覧][スレッド一覧]

ruby-changes:64947

From: Vladimir <ko1@a...>
Date: Tue, 19 Jan 2021 08:35:50 +0900 (JST)
Subject: [ruby-changes:64947] 1b89b99941 (master): Mark pattern labels as unremoveable

https://git.ruby-lang.org/ruby.git/commit/?id=1b89b99941

From 1b89b99941548fdb65305dd9a412082e7fdba45a Mon Sep 17 00:00:00 2001
From: Vladimir Dementyev <dementiev.vm@g...>
Date: Tue, 19 Jan 2021 00:00:52 +0300
Subject: 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

diff --git a/compile.c b/compile.c
index 916efb5..81ed8fd 100644
--- a/compile.c
+++ b/compile.c
@@ -6408,11 +6408,11 @@ compile_case3(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const orig_no https://github.com/ruby/ruby/blob/trunk/compile.c#L6408
             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");
diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb
index 243a4cd..e4c7507 100644
--- a/test/ruby/test_pattern_matching.rb
+++ b/test/ruby/test_pattern_matching.rb
@@ -791,6 +791,16 @@ END https://github.com/ruby/ruby/blob/trunk/test/ruby/test_pattern_matching.rb#L791
         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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]