Skip to content

Commit

Permalink
Allow f() = 1 = 2 to still parse
Browse files Browse the repository at this point in the history
This is semantically incorrect and will be caught by lowering. But
technically making it a parser error would be breaking :-(
  • Loading branch information
c42f committed Jul 19, 2024
1 parent 1d60e6d commit 5253bf4
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -618,18 +618,16 @@ function parse_assignment_with_initial_ex(ps::ParseState, mark, down::T) where {
parse_assignment(ps, down)
emit(ps, mark, is_dotted(t) ? K"dotcall" : K"call", INFIX_FLAG)
else
# f() = 1 ==> (function-= (call f) 1)
# f() .= 1 ==> (.= (call f) 1)
# a += b ==> (+= a b)
# a .= b ==> (.= a b)
is_short_form_func = k == K"=" && !is_dotted(t) && was_eventually_call(ps)
bump(ps, TRIVIA_FLAG)
bump_trivia(ps)
if is_short_form_func
# f() = 1
down(ps)
else
# f() .= 1
# a += b ==> (+= a b)
# a .= b ==> (.= a b)
parse_assignment(ps, down)
end
# Syntax Edition TODO: We'd like to call `down` here when
# is_short_form_func is true, to prevent `f() = 1 = 2` from parsing.
parse_assignment(ps, down)
emit(ps, mark,
is_short_form_func ? K"function" : k,
is_short_form_func ? SHORT_FORM_FUNCTION_FLAG : flags(t))
Expand Down

0 comments on commit 5253bf4

Please sign in to comment.