Skip to content

Commit

Permalink
fix JuliaLang#6074, macroexpander bug in let
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Mar 8, 2014
1 parent 3d0dcaf commit 85d13db
Showing 2 changed files with 43 additions and 9 deletions.
40 changes: 31 additions & 9 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
@@ -3090,17 +3090,24 @@ So far only the second case can actually occur.
(if (symbol? e) e
(cadr e)))

(define (new-expansion-env-for x env)
(append!
(filter (lambda (v)
(not (assq (car v) env)))
(append!
(pair-with-gensyms (vars-introduced-by x))
(map (lambda (v) (cons v v))
(keywords-introduced-by x))))
env))

(define (resolve-expansion-vars-with-new-env x env m inarg)
(resolve-expansion-vars-
x
(append!
(filter (lambda (x)
(not (assq (car x) env)))
(append!
(pair-with-gensyms (vars-introduced-by x))
(map (lambda (s) (cons s s))
(keywords-introduced-by x))))
env)
(if (and (pair? x) (eq? (car x) 'let))
;; let is strange in that it needs both old and new envs within
;; the same expression
env
(new-expansion-env-for x env))
m inarg))

(define (resolve-expansion-vars- e env m inarg)
@@ -3167,6 +3174,21 @@ So far only the second case can actually occur.
(cadr e))
,(resolve-expansion-vars- (caddr e) env m inarg))))

((let)
(let* ((newenv (new-expansion-env-for e env))
(body (resolve-expansion-vars- (cadr e) newenv m inarg))
;; expand initial values in old env
(rhss (map (lambda (a)
(resolve-expansion-vars- (caddr a) env m inarg))
(cddr e)))
;; expand binds in old env with dummy RHS
(lhss (map (lambda (a)
(cadr
(resolve-expansion-vars- (make-assignment (cadr a) 0)
newenv m inarg)))
(cddr e))))
`(let ,body ,@(map make-assignment lhss rhss))))

;; todo: trycatch
(else
(cons (car e)
@@ -3197,7 +3219,7 @@ So far only the second case can actually occur.
(if (or (not (pair? e)) (quoted? e))
'()
(case (car e)
((escape) '())
((escape let) '())
((= function)
(append! (filter
symbol?
12 changes: 12 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
@@ -1435,3 +1435,15 @@ function test6068()
a + 1
end
@test test6068() == 2

# issue #6074
macro X6074()
quote
global x6074
let x6074 = x6074
x6074
end
end
end
x6074 = 6074
@test @X6074() == 6074

0 comments on commit 85d13db

Please sign in to comment.