Skip to content

Commit

Permalink
fix #23558, bug in recursive let-bound functions
Browse files Browse the repository at this point in the history
Ref #23561
(cherry picked from commit aee1aab)
  • Loading branch information
JeffBezanson authored and ararslan committed Sep 13, 2017
1 parent 52415be commit 002f84c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1105,23 +1105,24 @@
;; some kind of assignment
(cond
((eventually-call? (cadar binds))
;; f()=c
;; f() = c
(let ((asgn (butlast (expand-forms (car binds))))
(name (assigned-name (cadar binds))))
(if (not (symbol? name))
(error "invalid let syntax"))
(loop (cdr binds)
`(scope-block
(block
(local-def ,name)
,(if (expr-contains-eq name (caddar binds))
`(local ,name) ;; might need a Box for recursive functions
`(local-def ,name))
,asgn
,blk)))))
((or (symbol? (cadar binds))
(decl? (cadar binds)))
(let ((vname (decl-var (cadar binds))))
(loop (cdr binds)
(if (contains (lambda (x) (eq? x vname))
(caddar binds))
(if (expr-contains-eq vname (caddar binds))
(let ((tmp (make-ssavalue)))
`(scope-block
(block (= ,tmp ,(caddar binds))
Expand Down
7 changes: 7 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ let f = i18408()
@test_throws UndefRefError f(0)
end

# issue #23558
c23558(n,k) =
let fact(n) = if (n == 0) 1 else n*fact(n-1) end
fact(n)/fact(k)/fact(n-k)
end
@test c23558(10, 5) == 252

# variable scope, globals
glob_x = 23
function glotest()
Expand Down

0 comments on commit 002f84c

Please sign in to comment.