Skip to content

Commit 3c02af9

Browse files
mlechuvtjnash
andauthored
lowering: Handle malformed ... expressions (#57480)
Fixes #51572. The expander had a looser definition of a vararg than the recursive logic destructing the vararg, so a bad expression like `(call f (... x y))` could cause a stack overflow via indestructible mutant semi-vararg. This change produces a saner error in this situation: ``` julia> macro foo(); Expr(:(...), 1, 2, 3); end; (@foo,) ERROR: syntax: wrong number of expressions following "..." around REPL[1]:1 Stacktrace: [1] top-level scope @ REPL[1]:1 ``` --------- Co-authored-by: Jameson Nash <vtjnash@gmail.com>
1 parent 414aca2 commit 3c02af9

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/ast.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@
449449
(check-dotop (cadr e))))))
450450
e)
451451

452-
(define (vararg? x) (and (pair? x) (eq? (car x) '...)))
452+
(define (vararg? x) (and (pair? x) (eq? (car x) '...) (length= x 2)))
453453
(define (vararg-type-expr? x)
454454
(or (eq? x 'Vararg)
455455
(and (length> x 1)

src/julia-syntax.scm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,8 +2691,7 @@
26912691
(if (null? run) '()
26922692
(list `(call (core tuple) ,.(reverse run))))
26932693
(let ((x (car a)))
2694-
(if (and (length= x 2)
2695-
(eq? (car x) '...))
2694+
(if (vararg? x)
26962695
(if (null? run)
26972696
(list* (cadr x)
26982697
(tuple-wrap (cdr a) '()))
@@ -2814,7 +2813,10 @@
28142813
'.>>>= lower-update-op
28152814

28162815
'|...|
2817-
(lambda (e) (error "\"...\" expression outside call"))
2816+
(lambda (e)
2817+
(if (not (length= e 2))
2818+
(error "wrong number of expressions following \"...\""))
2819+
(error "\"...\" expression outside call"))
28182820

28192821
'$
28202822
(lambda (e) (error "\"$\" expression outside quote"))

test/syntax.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ end
345345
# issue #15828
346346
@test Meta.lower(Main, Meta.parse("x...")) == Expr(:error, "\"...\" expression outside call")
347347

348+
# issue #57153 - malformed "..." expr
349+
@test Meta.lower(@__MODULE__, :(identity($(Expr(:(...), 1, 2, 3))))) ==
350+
(Expr(:error, "wrong number of expressions following \"...\""))
351+
348352
# issue #15830
349353
@test Meta.lower(Main, Meta.parse("foo(y = (global x)) = y")) == Expr(:error, "misplaced \"global\" declaration")
350354

0 commit comments

Comments
 (0)