Skip to content

Commit 47b6894

Browse files
committed
compile.c: Handle anonymous variables in outer_variable_cmp
[Bug #21370]
1 parent 87d340f commit 47b6894

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

compile.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13378,6 +13378,13 @@ outer_variable_cmp(const void *a, const void *b, void *arg)
1337813378
{
1337913379
const struct outer_variable_pair *ap = (const struct outer_variable_pair *)a;
1338013380
const struct outer_variable_pair *bp = (const struct outer_variable_pair *)b;
13381+
13382+
if (!ap->name) {
13383+
return -1;
13384+
} else if (!bp->name) {
13385+
return 1;
13386+
}
13387+
1338113388
return rb_str_cmp(ap->name, bp->name);
1338213389
}
1338313390

test/ruby/test_iseq.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,17 @@ def test_unreachable_next_in_block
859859
end
860860
end
861861

862+
def test_serialize_anonymous_outer_variables
863+
iseq = RubyVM::InstructionSequence.compile(<<~'RUBY')
864+
[1].each do
865+
rescue => e
866+
puts it
867+
end
868+
RUBY
869+
870+
iseq.to_binary # [Bug # 21370]
871+
end
872+
862873
def test_loading_kwargs_memory_leak
863874
assert_no_memory_leak([], "#{<<~"begin;"}", "#{<<~'end;'}", rss: true)
864875
a = iseq_to_binary(RubyVM::InstructionSequence.compile("foo(bar: :baz)"))

0 commit comments

Comments
 (0)