Skip to content

Commit 197292f

Browse files
headiuseregon
authored andcommitted
Specs for conditionally-assigned variables accessed in closure.
See jruby/jruby#4235
1 parent ad581ab commit 197292f

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

language/fixtures/variables.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,8 @@ def self.without_parenthesis a
7878
a
7979
end
8080
end
81+
82+
def self.false
83+
false
84+
end
8185
end

language/variables_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,27 @@ module VariableSpecs
750750
end
751751
end
752752
end
753+
754+
describe "A local variable assigned only within a conditional block" do
755+
context "accessed from a later closure" do
756+
it "is defined?" do
757+
if VariablesSpecs.false
758+
a = 1
759+
end
760+
761+
1.times do
762+
defined?(a).should == "local-variable"
763+
end
764+
end
765+
766+
it "is nil" do
767+
if VariablesSpecs.false
768+
a = 1
769+
end
770+
771+
1.times do
772+
a.inspect.should == "nil"
773+
end
774+
end
775+
end
776+
end

0 commit comments

Comments
 (0)