diff --git a/JuliaSyntax/src/julia/parser.jl b/JuliaSyntax/src/julia/parser.jl index aa644e1947eec..ea9286d2e6b9b 100644 --- a/JuliaSyntax/src/julia/parser.jl +++ b/JuliaSyntax/src/julia/parser.jl @@ -624,7 +624,7 @@ function parse_assignment_with_initial_ex(ps::ParseState, mark, down::T) where { # 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" : (isdot ? dotted(k) : k), + is_short_form_func ? K"function" : (isdot ? dotted(ps, k) : k), is_short_form_func ? SHORT_FORM_FUNCTION_FLAG : flags(t)) end end @@ -750,7 +750,7 @@ function parse_arrow(ps::ParseState) end end -function dotted(k) +function dotted(ps::ParseState, k) if k == K"||" return K".||" elseif k == K"&&" @@ -760,7 +760,8 @@ function dotted(k) elseif k == K"op=" return K".op=" else - error("Unexpected dotted operator: $k") + emit_diagnostic(ps, error = "Operator is invalid for broadcasting") + return K"error" end end @@ -773,7 +774,7 @@ function parse_lazy_cond(ps::ParseState, down, is_op, self) if is_op(k) bump_dotted(ps, isdot, TRIVIA_FLAG) self(ps) - emit(ps, mark, isdot ? dotted(k) : k, flags(t)) + emit(ps, mark, isdot ? dotted(ps, k) : k, flags(t)) if isdot min_supported_version(v"1.7", ps, mark, "dotted operators `.||` and `.&&`") end diff --git a/JuliaSyntax/test/parser_api.jl b/JuliaSyntax/test/parser_api.jl index 10a09d3ace585..6ebcfd5ff9ae5 100644 --- a/JuliaSyntax/test/parser_api.jl +++ b/JuliaSyntax/test/parser_api.jl @@ -112,6 +112,13 @@ @test parseshow("'abc'", ignore_errors=true) == "(char (ErrorOverLongCharacter))" @test parseshow("1e1000", ignore_errors=true) == "(ErrorNumericOverflow)" @test parseshow("1f1000", ignore_errors=true) == "(ErrorNumericOverflow)" + @testset "raise = false with invalid dotted operators" begin + result = Meta.parse("a .:= b"; raise = false) + @test Meta.isexpr(result, :error) + + result2 = Meta.parse("a .= b"; raise = false) + @test result2 == :(a .= b) + end end end