diff --git a/README.md b/README.md index fcd8d6d0e..8228fafef 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `==(::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]) +* `@__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]) + ## Renamed functions * `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively @@ -377,3 +379,4 @@ includes this fix. Find the minimum version from there. [#20500]: https://github.com/JuliaLang/julia/issues/20500 [#21257]: https://github.com/JuliaLang/julia/issues/21257 [#21346]: https://github.com/JuliaLang/julia/issues/21346 +[#22064]: https://github.com/JuliaLang/julia/issues/22064 diff --git a/src/Compat.jl b/src/Compat.jl index 0372c3268..699d77004 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1481,6 +1481,20 @@ else using Base: StringVector end +# https://github.com/JuliaLang/julia/pull/22064 +if !isdefined(Base, Symbol("@__MODULE__")) + export @__MODULE__ + macro __MODULE__() + return current_module() + end + Base.expand(mod::Module, x::ANY) = eval(mod, :(expand($(QuoteNode(x))))) + Base.macroexpand(mod::Module, x::ANY) = eval(mod, :(macroexpand($(QuoteNode(x))))) + Base.include_string(mod::Module, code::String, fname::String) = + eval(mod, :(include_string($code, $fname))) + Base.include_string(mod::Module, code::AbstractString, fname::AbstractString="string") = + eval(mod, :(include_string($code, $fname))) +end + # https://github.com/JuliaLang/julia/pull/19784 if isdefined(Base, :invokelatest) import Base.invokelatest diff --git a/test/runtests.jl b/test/runtests.jl index 88803de86..62938ab27 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1567,7 +1567,7 @@ A = view(rand(5,5), 1:3, 1:3) # julia#17623 if VERSION >= v"0.5.0-dev+5509" # Use include_string to work around unsupported syntax on Julia 0.4 -include_string(""" +include_string(Main, """ @test [true, false] .& [true, true] == [true, false] @test [true, false] .| [true, true] == [true, true] """) @@ -1852,6 +1852,8 @@ if VERSION >= v"0.5.0-rc1+46" @test b == [1,2,3] end +@test (@__MODULE__) === Main + # invokelatest issue19774(x) = 1 let foo() = begin @@ -1860,7 +1862,8 @@ let foo() = begin end @test foo() == 2 end -@test Compat.invokelatest(current_module) === current_module() +cm359() = @__MODULE__ +@test Compat.invokelatest(cm359) === @__MODULE__ # PR 21378 let