Skip to content

Commit

Permalink
Fix return nodes from case statements (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
castwide committed Aug 11, 2020
1 parent 35c0a92 commit fec9d59
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/solargraph/parser/rubyvm/node_methods.rb
Expand Up @@ -197,7 +197,7 @@ def get_return_nodes node
result.push node
result.concat get_return_nodes_only(node.children[1])
elsif node.type == :CASE
node.children.each do |cc|
node.children[1..-1].each do |cc|
result.concat reduce_to_value_nodes(cc.children[1..-1])
end
else
Expand Down
2 changes: 1 addition & 1 deletion lib/solargraph/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Solargraph
VERSION = '0.39.13'
VERSION = '0.39.14'
end
38 changes: 38 additions & 0 deletions spec/parser/node_methods_spec.rb
Expand Up @@ -61,6 +61,44 @@
expect(rets.length).to eq(2)
end

it 'handles return nodes from case statements' do
node = Solargraph::Parser.parse(%(
case x
when 100
true
end
))
returns = Solargraph::Parser::NodeMethods.returns_from(node)
# Include an implicit `nil` for missing else
expect(returns.length).to eq(2)
end

it 'handles return nodes from case statements with else' do
node = Solargraph::Parser.parse(%(
case x
when 100
true
else
false
end
))
returns = Solargraph::Parser::NodeMethods.returns_from(node)
expect(returns.length).to eq(2)
end

it 'handles return nodes from case statements with boolean conditions' do
node = Solargraph::Parser.parse(%(
case true
when x
true
else
false
end
))
returns = Solargraph::Parser::NodeMethods.returns_from(node)
expect(returns.length).to eq(2)
end

it "handles return nodes in reduceable (begin) nodes" do
# @todo Temporarily disabled. Result is 3 nodes instead of 2.
# node = Solargraph::Parser.parse(%(
Expand Down

0 comments on commit fec9d59

Please sign in to comment.