Skip to content

Commit

Permalink
Support keywords in invokelatest (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
omus authored Dec 6, 2017
1 parent 0a09689 commit 838890b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 838890b

Please sign in to comment.