Skip to content

Commit

Permalink
Merge pull request JuliaLang#21528 from JuliaLang/jb/fix21510
Browse files Browse the repository at this point in the history
fix JuliaLang#21510, keyword arg with declared type `ANY`
  • Loading branch information
JeffBezanson authored Apr 25, 2017
2 parents 5cdff93 + 04e6010 commit 741971f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,20 @@
(not (any (lambda (s)
(expr-contains-eq (car s) (caddr k)))
keyword-sparams)))
`(call (core typeassert)
,rval0
,(caddr k))
(let ((T (caddr k)))
`(call (core typeassert)
,rval0
;; work around `ANY` not being a type. if arg type
;; looks like `ANY`, test whether it is `ANY` at run
;; time and if so, substitute `Any`. issue #21510
,(if (or (eq? T 'ANY)
(and (globalref? T)
(eq? (caddr T) 'ANY)))
`(call (|.| (core Intrinsics) 'select_value)
(call (core ===) ,T (core ANY))
(core Any)
,T)
T)))
rval0)))
;; if kw[ii] == 'k; k = kw[ii+1]::Type; end
`(if (comparison ,elt === (quote ,(decl-var k)))
Expand Down
5 changes: 5 additions & 0 deletions test/keywordargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,8 @@ function g21147(f::Tuple{A}, k = 2) where {B,A<:Tuple{B}}
end
@test g21147(((1,),)) === Int
@test g21147(((1,),), 2) === Int

# issue #21510
f21510(; a::ANY = 2) = a
@test f21510(a=:b) == :b
@test f21510() == 2

0 comments on commit 741971f

Please sign in to comment.