diff --git a/README.md b/README.md index 670943803..cafd1ddb1 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,8 @@ Currently, the `@compat` macro supports the following syntaxes: but works in Julia 0.5+, and allows you to guarantee that a function call invokes the latest version of a function ([#19784]). +* `Compat.invokelatest` supports keywords ([#22646]). + * `Compat.StringVector` is supported on 0.5 and below. On 0.6 and later, it aliases `Base.StringVector`. This function allocates a `Vector{UInt8}` whose data can be made into a `String` in constant time; that is, without copying. On 0.5 and later, use `String(...)` with the vector allocated by `StringVector` as an argument to create a string without copying. Note that if 0.4 support is needed, `Compat.UTF8String(...)` should be used instead. ([#19449]) * `==(::Period, ::Period)` and `isless(::Period, ::Period)` is supported for 0.5 and below. Earlier versions of Julia only supported limited comparison methods between Periods which did not support comparing custom Period subtypes. ([#21378]) @@ -356,6 +358,7 @@ includes this fix. Find the minimum version from there. [#22512]: https://github.com/JuliaLang/julia/issues/22512 [#22629]: https://github.com/JuliaLang/julia/issues/22629 [#22633]: https://github.com/JuliaLang/julia/issues/22633 +[#22646]: https://github.com/JuliaLang/julia/issues/22646 [#22666]: https://github.com/JuliaLang/julia/issues/22666 [#22751]: https://github.com/JuliaLang/julia/issues/22751 [#22761]: https://github.com/JuliaLang/julia/issues/22761 diff --git a/src/Compat.jl b/src/Compat.jl index 3fd5256f4..a2b2684cd 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -490,10 +490,20 @@ end # https://github.com/JuliaLang/julia/pull/19784 @static if isdefined(Base, :invokelatest) - # 0.6 - import Base.invokelatest + # https://github.com/JuliaLang/julia/pull/22646 + if VERSION < v"0.7.0-DEV.1139" + function invokelatest(f, args...; kwargs...) + inner() = f(args...; kwargs...) + Base.invokelatest(inner) + end + else + import Base.invokelatest + end else - invokelatest(f, args...) = eval(current_module(), Expr(:call, f, map(QuoteNode, args)...)) + function invokelatest(f, args...; kwargs...) + kw = [Expr(:kw, k, QuoteNode(v)) for (k, v) in kwargs] + eval(current_module(), Expr(:call, f, map(QuoteNode, args)..., kw...)) + end end # https://github.com/JuliaLang/julia/pull/21257 diff --git a/test/runtests.jl b/test/runtests.jl index fb93f5aef..febea52cc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -652,6 +652,14 @@ end cm359() = @__MODULE__ @test Compat.invokelatest(cm359) === @__MODULE__ +pr22646(x; y=0) = 1 +let foo() = begin + eval(:(pr22646(x::Int; y=0) = 2)) + return Compat.invokelatest(pr22646, 0, y=1) + end + @test foo() == 2 +end + # PR 21378 let import Compat: Dates