Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support keywords in invokelatest #424

Merged
merged 1 commit into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(: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 @@ -650,6 +650,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