Skip to content

Commit

Permalink
fix handling of .op in lowering
Browse files Browse the repository at this point in the history
Discovered while running the syntax tests with lines 25-28 of
`jlfrontend.scm` commented out. Turned out we didn't handle `.op`
correctly in neither `check-dotop` nor in `deparse`. This meant we just
got `error: malformed expression` instead of an actually useful error
message.
  • Loading branch information
simeonschaub committed Mar 28, 2022
1 parent b297cc4 commit 0d77031
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/ast.scm
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@
((char? e) (string "'" e "'"))
((atom? e) (string e))
((eq? (car e) '|.|)
(string (deparse (cadr e)) '|.|
(cond ((and (pair? (caddr e)) (memq (caaddr e) '(quote inert)))
(deparse-colon-dot (cadr (caddr e))))
((and (pair? (caddr e)) (eq? (caaddr e) 'copyast))
(deparse-colon-dot (cadr (cadr (caddr e)))))
(else
(string #\( (deparse (caddr e)) #\))))))
(if (length= e 2)
(string "(." (deparse (cadr e)) ")")
(string (deparse (cadr e)) '|.|
(cond ((and (pair? (caddr e)) (memq (caaddr e) '(quote inert)))
(deparse-colon-dot (cadr (caddr e))))
((and (pair? (caddr e)) (eq? (caaddr e) 'copyast))
(deparse-colon-dot (cadr (cadr (caddr e)))))
(else
(string #\( (deparse (caddr e)) #\)))))))
((memq (car e) '(... |'|))
(string (deparse (cadr e)) (car e)))
((or (syntactic-op? (car e)) (eq? (car e) '|<:|) (eq? (car e) '|>:|) (eq? (car e) '-->))
Expand Down Expand Up @@ -445,7 +447,7 @@
(if (dotop-named? e)
(error (string "invalid function name \"" (deparse e) "\""))
(if (pair? e)
(if (eq? (car e) '|.|)
(if (and (eq? (car e) '|.|) (length= e 3))
(check-dotop (caddr e))
(if (quoted? e)
(check-dotop (cadr e))))))
Expand Down
2 changes: 1 addition & 1 deletion test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ f31404(a, b; kws...) = (a, b, values(kws))
# issue #28992
macro id28992(x) x end
@test @id28992(1 .+ 2) == 3
@test Meta.isexpr(Meta.lower(@__MODULE__, :(@id28992((.+)(a,b) = 0))), :error)
@test Meta.@lower(@id28992((.+)(a,b) = 0)) == Expr(:error, "invalid function name \"(.Main.+)\"")
@test @id28992([1] .< [2] .< [3]) == [true]
@test @id28992(2 ^ -2) == 0.25
@test @id28992(2 .^ -2) == 0.25
Expand Down

0 comments on commit 0d77031

Please sign in to comment.