Skip to content

Commit 0d77031

Browse files
committed
fix handling of .op in lowering
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.
1 parent b297cc4 commit 0d77031

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/ast.scm

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@
7979
((char? e) (string "'" e "'"))
8080
((atom? e) (string e))
8181
((eq? (car e) '|.|)
82-
(string (deparse (cadr e)) '|.|
83-
(cond ((and (pair? (caddr e)) (memq (caaddr e) '(quote inert)))
84-
(deparse-colon-dot (cadr (caddr e))))
85-
((and (pair? (caddr e)) (eq? (caaddr e) 'copyast))
86-
(deparse-colon-dot (cadr (cadr (caddr e)))))
87-
(else
88-
(string #\( (deparse (caddr e)) #\))))))
82+
(if (length= e 2)
83+
(string "(." (deparse (cadr e)) ")")
84+
(string (deparse (cadr e)) '|.|
85+
(cond ((and (pair? (caddr e)) (memq (caaddr e) '(quote inert)))
86+
(deparse-colon-dot (cadr (caddr e))))
87+
((and (pair? (caddr e)) (eq? (caaddr e) 'copyast))
88+
(deparse-colon-dot (cadr (cadr (caddr e)))))
89+
(else
90+
(string #\( (deparse (caddr e)) #\)))))))
8991
((memq (car e) '(... |'|))
9092
(string (deparse (cadr e)) (car e)))
9193
((or (syntactic-op? (car e)) (eq? (car e) '|<:|) (eq? (car e) '|>:|) (eq? (car e) '-->))
@@ -445,7 +447,7 @@
445447
(if (dotop-named? e)
446448
(error (string "invalid function name \"" (deparse e) "\""))
447449
(if (pair? e)
448-
(if (eq? (car e) '|.|)
450+
(if (and (eq? (car e) '|.|) (length= e 3))
449451
(check-dotop (caddr e))
450452
(if (quoted? e)
451453
(check-dotop (cadr e))))))

test/syntax.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ f31404(a, b; kws...) = (a, b, values(kws))
19171917
# issue #28992
19181918
macro id28992(x) x end
19191919
@test @id28992(1 .+ 2) == 3
1920-
@test Meta.isexpr(Meta.lower(@__MODULE__, :(@id28992((.+)(a,b) = 0))), :error)
1920+
@test Meta.@lower(@id28992((.+)(a,b) = 0)) == Expr(:error, "invalid function name \"(.Main.+)\"")
19211921
@test @id28992([1] .< [2] .< [3]) == [true]
19221922
@test @id28992(2 ^ -2) == 0.25
19231923
@test @id28992(2 .^ -2) == 0.25

0 commit comments

Comments
 (0)