Skip to content

Commit

Permalink
[PRISM] Recurse use_deconstructed_cache in Alternation Nodes
Browse files Browse the repository at this point in the history
This fixes the behavioural difference between Prism and parse.y when
evaluating the following code

```ruby
1 in [1 | [1]]
```

Fixes [Bug #20956]
  • Loading branch information
eightbitraptor committed Dec 17, 2024
1 parent c25dd4e commit bf3b1a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions prism_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2991,7 +2991,7 @@ pm_compile_pattern(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_node_t
// First, we're going to attempt to match against the left pattern. If
// that pattern matches, then we'll skip matching the right pattern.
PUSH_INSN(ret, location, dup);
CHECK(pm_compile_pattern(iseq, scope_node, cast->left, ret, matched_left_label, unmatched_left_label, in_single_pattern, true, true, base_index + 1));
CHECK(pm_compile_pattern(iseq, scope_node, cast->left, ret, matched_left_label, unmatched_left_label, in_single_pattern, true, use_deconstructed_cache, base_index + 1));

// If we get here, then we matched on the left pattern. In this case we
// should pop out the duplicate value that we preemptively added to
Expand All @@ -3004,7 +3004,7 @@ pm_compile_pattern(rb_iseq_t *iseq, pm_scope_node_t *scope_node, const pm_node_t
// If we get here, then we didn't match on the left pattern. In this
// case we attempt to match against the right pattern.
PUSH_LABEL(ret, unmatched_left_label);
CHECK(pm_compile_pattern(iseq, scope_node, cast->right, ret, matched_label, unmatched_label, in_single_pattern, true, true, base_index));
CHECK(pm_compile_pattern(iseq, scope_node, cast->right, ret, matched_label, unmatched_label, in_single_pattern, true, use_deconstructed_cache, base_index));
break;
}
case PM_PARENTHESES_NODE:
Expand Down
3 changes: 3 additions & 0 deletions test/ruby/test_compile_prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,9 @@ def test_MatchPredicateNode
assert_prism_eval("5 in foo")

assert_prism_eval("1 in 2")

# Bug: https://bugs.ruby-lang.org/issues/20956
assert_prism_eval("1 in [1 | [1]]")
end

def test_MatchRequiredNode
Expand Down

0 comments on commit bf3b1a7

Please sign in to comment.