Skip to content

Commit

Permalink
invokelatest (from #352 and #359)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Sep 10, 2018
1 parent bd7f2db commit 8442dae
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ Currently, the `@compat` macro supports the following syntaxes:

* The `isabstract`, `parameter_upper_bound`, `typename` reflection methods were added in Julia 0.6. This package re-exports these from the `Compat.TypeUtils` submodule. On earlier versions of julia, that module contains the same functions, but operating on the pre-0.6 type system representation.

* `Compat.invokelatest` is equivalent to `Base.invokelatest` in Julia 0.6,
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]).

* `@__MODULE__` is aliased to `current_module()` for Julia versions 0.6 and below. Versions of `Base.binding_module`, `expand`, `macroexpand`, and `include_string` were added that accept a module as the first argument. ([#22064])
Expand Down Expand Up @@ -454,7 +450,6 @@ includes this fix. Find the minimum version from there.
[#13681]: https://github.com/JuliaLang/julia/issues/13681
[#17302]: https://github.com/JuliaLang/julia/issues/17302
[#17323]: https://github.com/JuliaLang/julia/issues/17323
[#19784]: https://github.com/JuliaLang/julia/issues/19784
[#20005]: https://github.com/JuliaLang/julia/issues/20005
[#20974]: https://github.com/JuliaLang/julia/issues/20974
[#21197]: https://github.com/JuliaLang/julia/issues/21197
Expand Down
20 changes: 6 additions & 14 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,14 @@ end
# TODO deprecate/remove this unexported binding (along wiht its tests)
using Base: StringVector

# https://github.com/JuliaLang/julia/pull/19784
@static if isdefined(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
# https://github.com/JuliaLang/julia/pull/22646
if VERSION < v"0.7.0-DEV.1139"
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...))
inner() = f(args...; kwargs...)
Base.invokelatest(inner)
end
else
import Base.invokelatest
end

# https://github.com/JuliaLang/julia/pull/21197
Expand Down
12 changes: 1 addition & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,7 @@ using Compat.Test
@test (@__MODULE__) === Test22064
end

# invokelatest
issue19774(x) = 1
let foo() = begin
eval(:(issue19774(x::Int) = 2))
return Compat.invokelatest(issue19774, 0)
end
@test foo() == 2
end
cm359() = @__MODULE__
@test Compat.invokelatest(cm359) === @__MODULE__

# invokelatest with keywords
pr22646(x; y=0) = 1
let foo() = begin
eval(:(pr22646(x::Int; y=0) = 2))
Expand Down

0 comments on commit 8442dae

Please sign in to comment.