Skip to content

Commit

Permalink
fix JuliaLang#9948, scoping bug in keyword arg defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson authored and mfasi committed Sep 5, 2016
1 parent 53b9c03 commit 610e45b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@
,@lno
,@(if (not ordered-defaults)
'()
(map make-assignment keynames vals))
(append! (map (lambda (kwname) `(local ,kwname)) keynames)
(map make-assignment keynames vals)))
;; call mangled(vals..., [rest_kw ,]pargs..., [vararg]...)
(return (call ,mangled
,@(if ordered-defaults keynames vals)
Expand Down Expand Up @@ -466,6 +467,7 @@
`(block
;; initialize keyword args to their defaults, or set a flag telling
;; whether this keyword needs to be set.
,@(map (lambda (kwname) `(local ,kwname)) keynames)
,@(map (lambda (name dflt flag)
(if (const-default? dflt)
`(= ,name ,dflt)
Expand Down
13 changes: 13 additions & 0 deletions test/keywordargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,16 @@ end
@test ((a=1,b=2)->(a,b))() == (1,2)
@test ((a=1,b=2)->(a,b))(5) == (5,2)
@test ((a=1,b=2)->(a,b))(5,6) == (5,6)

# issue #9948
f9948, getx9948 = let
x = 3
h(;x=x) = x
getx() = x
h, getx
end
@test_throws UndefVarError f9948()
@test getx9948() == 3
@test f9948(x=5) == 5
@test_throws UndefVarError f9948()
@test getx9948() == 3

0 comments on commit 610e45b

Please sign in to comment.