Skip to content

Commit

Permalink
Fixed #4399: a.field=(expr)... and a.field = (expr)... are parsed…
Browse files Browse the repository at this point in the history
… differently
  • Loading branch information
asterite committed Jun 7, 2017
1 parent b7e9237 commit ca47207
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Expand Up @@ -1276,6 +1276,8 @@ describe "Parser" do

it_parses "yield foo do\nend", Yield.new([Call.new(nil, "foo", block: Block.new)] of ASTNode)

it_parses "x.y=(1).to_s", Call.new("x".call, "y=", Call.new(Expressions.new([1.int32] of ASTNode), "to_s"))

assert_syntax_error "return do\nend", "unexpected token: do"

%w(def macro class struct module fun alias abstract include extend lib).each do |keyword|
Expand Down
17 changes: 13 additions & 4 deletions src/compiler/crystal/syntax/parser.cr
Expand Up @@ -640,10 +640,19 @@ module Crystal
next_token

if @token.type == :"("
next_token_skip_space
arg = parse_single_arg
check :")"
next_token
# If we have `f.x=(exp1).a.b.c`, consider it the same as `f.x = (exp1).a.b.c`
# and not as `(f.x = exp1).a.b.c` because a difference in space
# should not make a difference in semantic (#4399)
# The only exception is doing a splat, in which case this can only
# be expanded arguments for the call.
if current_char == '*'
next_token_skip_space
arg = parse_single_arg
check :")"
next_token
else
arg = parse_op_assign_no_control
end
else
skip_space_or_newline
arg = parse_single_arg
Expand Down

0 comments on commit ca47207

Please sign in to comment.