Skip to content

Commit

Permalink
Merge pull request #20525 from JuliaLang/jb/fix20524
Browse files Browse the repository at this point in the history
fix #20524, macros not handling nested tuple destructuring
  • Loading branch information
JeffBezanson authored Feb 9, 2017
2 parents c027cf4 + 27f3846 commit ddb1e1e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/ast.scm
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@
(define (ssavalue? e)
(and (pair? e) (eq? (car e) 'ssavalue)))

(define (globalref? e)
(and (pair? e) (eq? (car e) 'globalref)))

(define (symbol-like? e)
(or (and (symbol? e) (not (eq? e 'true)) (not (eq? e 'false)))
(ssavalue? e)))
Expand Down
2 changes: 1 addition & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2381,7 +2381,7 @@
((=)
(let ((v (decl-var (cadr e)))
(rest (find-assigned-vars (caddr e) env)))
(if (or (ssavalue? v) (memq v env))
(if (or (ssavalue? v) (memq v env) (globalref? v))
rest
(cons v rest))))
(else
Expand Down
11 changes: 6 additions & 5 deletions src/macroexpand.scm
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@
((eq? (car e) 'curly) (decl-var* (cadr e)))
(else (decl-var e))))

(define (decl-vars* e)
(if (and (pair? e) (eq? (car e) 'tuple))
(apply append (map decl-vars* (cdr e)))
(list (decl-var* e))))

(define (function-def? e)
(and (pair? e) (or (eq? (car e) 'function) (eq? (car e) '->)
(and (eq? (car e) '=) (length= e 3)
Expand Down Expand Up @@ -340,11 +345,7 @@
(list fname)
'())))
((and (eq? (car e) '=) (not (function-def? e)))
(append! (filter
symbol?
(if (and (pair? (cadr e)) (eq? (car (cadr e)) 'tuple))
(map decl-var* (cdr (cadr e)))
(list (decl-var* (cadr e)))))
(append! (filter symbol? (decl-vars* (cadr e)))
(find-assigned-vars-in-expansion (caddr e) #f)))
(else
(apply append! (map (lambda (x)
Expand Down
13 changes: 13 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,19 @@ let
@test f5876(Int) === Int
end

# issue #20524
macro m20524(ex)
quote
global f20524
function f20524()
$ex
end
end
end
@m20524 ((a,(b20524,c)) = (8,(1,5)); (a,b20524,c))
@test f20524() === (8,1,5)
@test !isdefined(:b20524) # should not assign to a global

# issue #6387
bitstype 64 Date6387{C}

Expand Down

0 comments on commit ddb1e1e

Please sign in to comment.