From 27f3846e236da4e2c9feda6c755af8d505fbc4cc Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 8 Feb 2017 15:03:26 -0500 Subject: [PATCH] fix #20524, macros not handling nested tuple destructuring also don't recognize assigned globalrefs as potential local variables in lowering --- src/ast.scm | 3 +++ src/julia-syntax.scm | 2 +- src/macroexpand.scm | 11 ++++++----- test/core.jl | 13 +++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/ast.scm b/src/ast.scm index 1e26777396142..2541b1cb1edd0 100644 --- a/src/ast.scm +++ b/src/ast.scm @@ -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))) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 39536bdac5e7e..32839ce1499d4 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -2374,7 +2374,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 diff --git a/src/macroexpand.scm b/src/macroexpand.scm index 0f05868f2560b..2258a8b41f4d1 100644 --- a/src/macroexpand.scm +++ b/src/macroexpand.scm @@ -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) @@ -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) diff --git a/test/core.jl b/test/core.jl index f5499e64f4d1b..5676e566bd244 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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}