Skip to content

Commit

Permalink
fix #30772, problem capturing static parameters in inner function sig…
Browse files Browse the repository at this point in the history
…nature (#30781)
  • Loading branch information
JeffBezanson authored Jan 22, 2019
1 parent 10ada8e commit e93a3ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2594,7 +2594,7 @@
(define (free-vars e)
(table.keys (free-vars- e (table))))

(define (analyze-vars-lambda e env captvars sp new-sp)
(define (analyze-vars-lambda e env captvars sp new-sp (methsig #f))
(let* ((args (lam:args e))
(locl (caddr e))
(allv (nconc (map arg-name args) locl))
Expand All @@ -2605,13 +2605,15 @@
(if vi (free-vars (vinfo:type vi)) '())))
fv))))
(append (diff dv fv) fv)))
(sig-fv (if methsig (free-vars methsig) '()))
(glo (find-global-decls (lam:body e)))
;; make var-info records for vars introduced by this lambda
(vi (nconc
(map (lambda (decl) (make-var-info (decl-var decl)))
args)
(map make-var-info locl)))
(capt-sp (filter (lambda (v) (and (memq v fv) (not (memq v glo)) (not (memq v new-sp))))
(capt-sp (filter (lambda (v) (or (and (memq v fv) (not (memq v glo)) (not (memq v new-sp)))
(memq v sig-fv)))
sp))
;; captured vars: vars from the environment that occur
;; in our set of free variables (fv).
Expand Down Expand Up @@ -2694,7 +2696,8 @@
(begin (analyze-vars (caddr e) env captvars sp)
(assert (eq? (car (cadddr e)) 'lambda))
(analyze-vars-lambda (cadddr e) env captvars sp
(method-expr-static-parameters e)))))
(method-expr-static-parameters e)
(caddr e)))))
((module toplevel) e)
(else (for-each (lambda (x) (analyze-vars x env captvars sp))
(cdr e))))))
Expand Down
12 changes: 12 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1780,3 +1780,15 @@ end
f30656(T) = (t, _)::Pair -> t >= T
f30656(10)(11=>1)
@test !isdefined(@__MODULE__, :_)

# issue #30772
function f30772(a::T) where T
function ()
function (b::T)
end
end
end
let f = f30772(1.0), g = f()
@test g(1.0) === nothing
@test_throws MethodError g(1)
end

2 comments on commit e93a3ca

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.