Skip to content

Commit c908046

Browse files
simeonschaubKristofferC
authored andcommitted
errors: fix handling of .op in lowering (#44770)
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. (cherry picked from commit 9112135)
1 parent 16944c3 commit c908046

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/ast.scm

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@
7373
((char? e) (string "'" e "'"))
7474
((atom? e) (string e))
7575
((eq? (car e) '|.|)
76-
(string (deparse (cadr e)) '|.|
77-
(cond ((and (pair? (caddr e)) (memq (caaddr e) '(quote inert)))
78-
(deparse-colon-dot (cadr (caddr e))))
79-
((and (pair? (caddr e)) (eq? (caaddr e) 'copyast))
80-
(deparse-colon-dot (cadr (cadr (caddr e)))))
81-
(else
82-
(string #\( (deparse (caddr e)) #\))))))
76+
(if (length= e 2)
77+
(string "(." (deparse (cadr e)) ")")
78+
(string (deparse (cadr e)) '|.|
79+
(cond ((and (pair? (caddr e)) (memq (caaddr e) '(quote inert)))
80+
(deparse-colon-dot (cadr (caddr e))))
81+
((and (pair? (caddr e)) (eq? (caaddr e) 'copyast))
82+
(deparse-colon-dot (cadr (cadr (caddr e)))))
83+
(else
84+
(string #\( (deparse (caddr e)) #\)))))))
8385
((memq (car e) '(... |'|))
8486
(string (deparse (cadr e)) (car e)))
8587
((or (syntactic-op? (car e)) (eq? (car e) '|<:|) (eq? (car e) '|>:|) (eq? (car e) '-->))
@@ -419,7 +421,7 @@
419421
(if (dotop-named? e)
420422
(error (string "invalid function name \"" (deparse e) "\""))
421423
(if (pair? e)
422-
(if (eq? (car e) '|.|)
424+
(if (and (eq? (car e) '|.|) (length= e 3))
423425
(check-dotop (caddr e))
424426
(if (quoted? e)
425427
(check-dotop (cadr e))))))

test/syntax.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,12 @@ f31404(a, b; kws...) = (a, b, kws.data)
18891889
# issue #28992
18901890
macro id28992(x) x end
18911891
@test @id28992(1 .+ 2) == 3
1892-
@test Meta.isexpr(Meta.lower(@__MODULE__, :(@id28992((.+)(a,b) = 0))), :error)
1892+
@test Meta.@lower(.+(a,b) = 0) == Expr(:error, "invalid function name \".+\"")
1893+
@test Meta.@lower((.+)(a,b) = 0) == Expr(:error, "invalid function name \"(.+)\"")
1894+
let m = @__MODULE__
1895+
@test Meta.lower(m, :($m.@id28992(.+(a,b) = 0))) == Expr(:error, "invalid function name \"$(nameof(m)).:.+\"")
1896+
@test Meta.lower(m, :($m.@id28992((.+)(a,b) = 0))) == Expr(:error, "invalid function name \"(.$(nameof(m)).+)\"")
1897+
end
18931898
@test @id28992([1] .< [2] .< [3]) == [true]
18941899
@test @id28992(2 ^ -2) == 0.25
18951900
@test @id28992(2 .^ -2) == 0.25

0 commit comments

Comments
 (0)