Skip to content

Commit 594fafc

Browse files
authored
add invokelatest from Julia 0.6 (#352)
* add invokelatest from Julia 0.6
1 parent d5bc9f9 commit 594fafc

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ Currently, the `@compat` macro supports the following syntaxes:
165165

166166
* `bswap` is supported for `Complex` arguments on 0.5 and below. ([#21346])
167167

168+
* `Compat.invokelatest` is equivalent to `Base.invokelatest` in Julia 0.6,
169+
but works in Julia 0.4+, and allows you to guarantee that a function call
170+
invokes the latest version of a function ([#19784]).
171+
168172
* `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])
169173

170174
## Renamed functions
@@ -343,16 +347,19 @@ includes this fix. Find the minimum version from there.
343347
[#17323]: https://github.com/JuliaLang/julia/issues/17323
344348
[#17510]: https://github.com/JuliaLang/julia/issues/17510
345349
[#17623]: https://github.com/JuliaLang/julia/issues/17623
346-
[#18086]: https://github.com/JuliaLang/julia/issues/18086
350+
[#18082]: https://github.com/JuliaLang/julia/issues/18082
347351
[#18380]: https://github.com/JuliaLang/julia/issues/18380
348352
[#18484]: https://github.com/JuliaLang/julia/issues/18484
349353
[#18510]: https://github.com/JuliaLang/julia/issues/18510
354+
[#18629]: https://github.com/JuliaLang/julia/issues/18629
350355
[#18727]: https://github.com/JuliaLang/julia/issues/18727
351356
[#18839]: https://github.com/JuliaLang/julia/issues/18839
352357
[#18977]: https://github.com/JuliaLang/julia/issues/18977
353358
[#19088]: https://github.com/JuliaLang/julia/issues/19088
354359
[#19246]: https://github.com/JuliaLang/julia/issues/19246
360+
[#19449]: https://github.com/JuliaLang/julia/issues/19449
355361
[#19635]: https://github.com/JuliaLang/julia/issues/19635
362+
[#19784]: https://github.com/JuliaLang/julia/issues/19784
356363
[#19841]: https://github.com/JuliaLang/julia/issues/19841
357364
[#19950]: https://github.com/JuliaLang/julia/issues/19950
358365
[#20022]: https://github.com/JuliaLang/julia/issues/20022
@@ -363,6 +370,5 @@ includes this fix. Find the minimum version from there.
363370
[#20414]: https://github.com/JuliaLang/julia/issues/20414
364371
[#20418]: https://github.com/JuliaLang/julia/issues/20418
365372
[#20500]: https://github.com/JuliaLang/julia/issues/20500
366-
[#18629]: https://github.com/JuliaLang/julia/pull/18629
367-
[#21346]: https://github.com/JuliaLang/julia/pull/21346
368-
[#21257]: https://github.com/JuliaLang/julia/pull/21257
373+
[#21257]: https://github.com/JuliaLang/julia/issues/21257
374+
[#21346]: https://github.com/JuliaLang/julia/issues/21346

src/Compat.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,13 @@ else
14711471
using Base: StringVector
14721472
end
14731473

1474+
# https://github.com/JuliaLang/julia/pull/19784
1475+
if isdefined(Base, :invokelatest)
1476+
import Base.invokelatest
1477+
else
1478+
invokelatest(f, args...) = eval(Expr(:call, f, map(QuoteNode, args)...))
1479+
end
1480+
14741481
# https://github.com/JuliaLang/julia/pull/21257
14751482
if v"0.5.0-rc1+46" <= VERSION < v"0.6.0-pre.beta.28"
14761483
collect(A) = collect_indices(indices(A), A)

test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,15 @@ if VERSION >= v"0.5.0-rc1+46"
18401840
@test b == [1,2,3]
18411841
end
18421842

1843+
# invokelatest
1844+
issue19774(x) = 1
1845+
let foo() = begin
1846+
eval(:(issue19774(x::Int) = 2))
1847+
return Compat.invokelatest(issue19774, 0)
1848+
end
1849+
@test foo() == 2
1850+
end
1851+
18431852
include("to-be-deprecated.jl")
18441853

18451854
nothing

0 commit comments

Comments
 (0)