Skip to content

Commit

Permalink
Fix checks for void value expression
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Feb 27, 2023
1 parent 9690325 commit 5c115aa
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions language/if_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,49 @@
ScratchPad.recorded.should == [4, 5, 4, 5]
end
end

describe "when a branch syntactically does not return a value" do
it "raises SyntaxError if both do not return a value" do
-> {
eval <<~RUBY
def m
a = if rand
return
else
return
end
a
end
RUBY
}.should raise_error(SyntaxError, /void value expression/)
end

it "does not raise SyntaxError if one branch returns a value" do
eval(<<~RUBY).should == 1
def m
a = if false # using false to make it clear that's not checked for
42
else
return 1
end
a
end
m
RUBY

eval(<<~RUBY).should == 1
def m
a = if true # using true to make it clear that's not checked for
return 1
else
42
end
a
end
m
RUBY
end
end
end

describe "The postfix if form" do
Expand Down

0 comments on commit 5c115aa

Please sign in to comment.