Skip to content

Commit

Permalink
Parser: fixed wrong parsing of tuple with one element followed by new…
Browse files Browse the repository at this point in the history
…line and brace. Fixes #3779
  • Loading branch information
asterite committed Dec 25, 2016
1 parent 56df571 commit a3ea7ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,8 @@ describe "Parser" do
it_parses "{1, 2, 3}", TupleLiteral.new([1.int32, 2.int32, 3.int32] of ASTNode)
it_parses "{A::B}", TupleLiteral.new([Path.new(["A", "B"])] of ASTNode)
it_parses "{\n1,\n2\n}", TupleLiteral.new([1.int32, 2.int32] of ASTNode)
it_parses "{\n1\n}", TupleLiteral.new([1.int32] of ASTNode)
it_parses "{\n{1}\n}", TupleLiteral.new([TupleLiteral.new([1.int32] of ASTNode)] of ASTNode)

it_parses "foo { a = 1 }; a", [Call.new(nil, "foo", block: Block.new(body: Assign.new("a".var, 1.int32))), "a".call] of ASTNode

Expand Down
4 changes: 4 additions & 0 deletions src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,10 @@ module Crystal
return parse_tuple first_key, location
when :"}"
return parse_tuple first_key, location
when :NEWLINE
next_token_skip_space
check :"}"
return parse_tuple first_key, location
else
check :"=>"
end
Expand Down

0 comments on commit a3ea7ad

Please sign in to comment.