diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 0b099375d97e4..0adfd65f28d5e 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -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))) diff --git a/test/keywordargs.jl b/test/keywordargs.jl index 14199e2bc7a66..5a0abed112104 100644 --- a/test/keywordargs.jl +++ b/test/keywordargs.jl @@ -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