diff --git a/lib/ruby2ruby.rb b/lib/ruby2ruby.rb index a3fb5af..d68d828 100755 --- a/lib/ruby2ruby.rb +++ b/lib/ruby2ruby.rb @@ -609,7 +609,11 @@ def process_in exp # :nodoc: _, lhs, *rhs = exp cond = process lhs - body = rhs.compact.map { |sexp| indent process sexp } + body = rhs.compact.map { |sexp| + in_context :in_body do + indent process sexp + end + } body << indent("# do nothing") if body.empty? body = body.join "\n" diff --git a/test/test_ruby2ruby.rb b/test/test_ruby2ruby.rb index 2def801..b57a14d 100644 --- a/test/test_ruby2ruby.rb +++ b/test/test_ruby2ruby.rb @@ -1002,6 +1002,16 @@ def test_case_in__hash_pat_14 assert_case_in "Object[b: 1]", s(:hash_pat, s(:const, :Object), s(:lit, :b), s(:lit, 1)) end + def test_case_in_body_does_not_pin_variables + inn = s(:case, s(:call, nil, :x), + s(:in, + s(:array_pat, nil, s(:lasgn, :a), s(:lasgn, :b)), + s(:lvar, :a)), + nil) + out = "case x\nin [a, b] then\n a\nend" + assert_parse inn, out + end + def test_interpolation_and_escapes # log_entry = " \e[#{message_color}m#{message}\e[0m " inn = s(:lasgn, :log_entry,