diff options
| author | eileencodes <eileencodes@gmail.com> | 2023-12-12 13:44:33 -0500 |
|---|---|---|
| committer | Jemma Issroff <jemmaissroff@gmail.com> | 2023-12-12 15:15:02 -0500 |
| commit | a6526342f3fbd94abc44cc4e99eda0943a61271f (patch) | |
| tree | 41b404968c00608379e92ba142726f8c4b449837 | |
| parent | 1572322e17caf2f0900f02099d21245b81554a28 (diff) | |
[PRISM] Fix segv with regex once flag
When you have an interpolated regex with a `once` flag and local
variable is outside the block created by the `once` flag, Prism would
see a segv. This is because it was not taking the depth into account.
To fix this, we need to add 1 to the `local_depth_offset` on the
`scope`.
Fixes: ruby/prism#2047
| -rw-r--r-- | prism_compile.c | 1 | ||||
| -rw-r--r-- | test/ruby/test_compile_prism.rb | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/prism_compile.c b/prism_compile.c index 2f0161fb47..95544ccda1 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -1437,6 +1437,7 @@ pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_ case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: { RUBY_ASSERT(node->flags & PM_REGULAR_EXPRESSION_FLAGS_ONCE); scope->body = (pm_node_t *)node; + scope->local_depth_offset += 1; break; } case PM_LAMBDA_NODE: { diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index e95baf5d5c..0409fc3e46 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -601,6 +601,7 @@ module Prism assert_prism_eval('/pit/ne') assert_prism_eval('2.times.map { /#{1}/o }') + assert_prism_eval('2.times.map { foo = 1; /#{foo}/o }') end def test_StringNode |
