From 9791d7fedfe0ca13e9a4a37e1f3b4e640b3298cc Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Mon, 4 Dec 2017 17:04:12 -0600 Subject: [PATCH] Support keywords in invokelatest --- README.md | 3 +++ src/Compat.jl | 16 +++++++++++++--- test/runtests.jl | 8 ++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 60418ed75..2535f1240 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]) @@ -352,6 +354,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 220409f13..1eb11b1db 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -485,10 +485,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(:parameters, [Expr(:kw, k, QuoteNode(v)) for (k, v) in kwargs]...) + eval(current_module(), Expr(:call, f, kw, map(QuoteNode, args)...)) + end end # https://github.com/JuliaLang/julia/pull/21257 diff --git a/test/runtests.jl b/test/runtests.jl index b842ec337..1cd68dfd8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -650,6 +650,14 @@ end cm359() = @__MODULE__ @test Compat.invokelatest(cm359) === @__MODULE__ +pr22646(; y=0) = 1 +let foo() = begin + eval(:(pr22646(; y=0) = 2)) + return Compat.invokelatest(pr22646, y=1) + end + @test foo() == 2 +end + # PR 21378 let import Compat: Dates