Skip to content

Commit

Permalink
Fix to expand case with assignment wrapped by paren
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust committed Dec 30, 2017
1 parent 86a4bb0 commit c07aa1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/compiler/normalize/case_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ describe "Normalize: case" do
assert_expand "case x = 1; when 2; 3; end", "x = 1\nif 2 === x\n 3\nend"
end

it "normalizes case with assignment wrapped by paren" do
assert_expand "case (x = 1); when 2; 3; end", "x = 1\nif 2 === x\n 3\nend"
end

it "normalizes case without value" do
assert_expand "case when 2; 3; when 4; 5; end", "if 2\n 3\nelse\n if 4\n 5\n end\nend"
end
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/crystal/semantic/literal_expander.cr
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ module Crystal

assigns = [] of ASTNode
temp_vars = conds.map do |cond|
if cond.is_a?(Expressions) && cond.expressions.size == 1
cond = cond[0]
end

case cond
when Var, InstanceVar
temp_var = cond
Expand Down

0 comments on commit c07aa1a

Please sign in to comment.