Skip to content

Commit dc89240

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 9daeadd commit dc89240

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
@@ -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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,12 @@ f31404(a, b; kws...) = (a, b, values(kws))
19091909
# issue #28992
19101910
macro id28992(x) x end
19111911
@test @id28992(1 .+ 2) == 3
1912-
@test Meta.isexpr(Meta.lower(@__MODULE__, :(@id28992((.+)(a,b) = 0))), :error)
1912+
@test Meta.@lower(.+(a,b) = 0) == Expr(:error, "invalid function name \".+\"")
1913+
@test Meta.@lower((.+)(a,b) = 0) == Expr(:error, "invalid function name \"(.+)\"")
1914+
let m = @__MODULE__
1915+
@test Meta.lower(m, :($m.@id28992(.+(a,b) = 0))) == Expr(:error, "invalid function name \"$(nameof(m)).:.+\"")
1916+
@test Meta.lower(m, :($m.@id28992((.+)(a,b) = 0))) == Expr(:error, "invalid function name \"(.$(nameof(m)).+)\"")
1917+
end
19131918
@test @id28992([1] .< [2] .< [3]) == [true]
19141919
@test @id28992(2 ^ -2) == 0.25
19151920
@test @id28992(2 .^ -2) == 0.25

0 commit comments

Comments
 (0)