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

Add public to the @compat macro #805

Merged
merged 6 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Compat"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "4.9.0"
version = "4.10.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ changes in `julia`.

## Supported features

* `@public` as an alias for the `public` keyword (no-op on Julia 1.10 and earlier). ([#50105]) (since Compat 4.10.0)

* `sort` for `NTuple` and other iterables. ([#46104]) (since Compat 4.9.0)

* `redirect_stdio`, for simple stream redirection. ([#37978]) (since Compat 4.8.0)
Expand Down Expand Up @@ -172,3 +174,4 @@ Note that you should specify the correct minimum version for `Compat` in the
[#43852]: https://github.com/JuliaLang/julia/issues/43852
[#46104]: https://github.com/JuliaLang/julia/issues/46104
[#48038]: https://github.com/JuliaLang/julia/issues/48038
[#50105]: https://github.com/JuliaLang/julia/issues/50105
27 changes: 26 additions & 1 deletion src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ end
if VERSION < v"1.9.0-DEV.1163"
import Base: IteratorSize, HasLength, HasShape, OneTo
export stack

"""
stack(iter; [dims])

Expand Down Expand Up @@ -741,6 +741,31 @@ if VERSION < v"1.10.0-DEV.1404"
(lt(o, y[1], x[1]) ? (y[1], merge(x, tail(y), o)...) : (x[1], merge(tail(x), y, o)...))
end

# https://github.com/JuliaLang/julia/pull/50105
export @public
"""
@public foo, bar, baz

Equivalent to `public foo, bar, baz` on versions of Julia that support the `public` keyword;
a no-op on versions of Julia that do not support the `public` keyword.
"""
macro public(arg)
symbols = _get_symbols(arg)
if VERSION >= v"1.11.0-DEV.469"
esc(Expr(:public, symbols...))
end
end

_get_symbols(symbol::Symbol) = (symbol,)
function _get_symbols(symbols)
if Base.isexpr(symbols, :tuple) && all(x -> x isa Symbol, symbols.args)
LilithHafner marked this conversation as resolved.
Show resolved Hide resolved
symbols.args
else
throw(ArgumentError("cannot mark `$symbols` as public. Try `@public foo, bar, baz`."))
end
end


include("deprecated.jl")

end # module Compat
20 changes: 19 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ end

# https://github.com/JuliaLang/julia/pull/43852
@testset "@assume_effects" begin
# ensure proper macro hygiene across versions
# ensure proper macro hygiene across versions
Compat.@assume_effects :total foo() = true
Compat.@assume_effects bar() = true
@test foo()
Expand Down Expand Up @@ -724,3 +724,21 @@ end
@test_throws ArgumentError("1 cannot be sorted") sort(1)
end
end

module Mod50105
using Compat
@public foo, bar, baz
end

# https://github.com/JuliaLang/julia/pull/50105
@testset "@public" begin
@public foo_50105
# foo_50105 = 4 # Uncommenting this line would cause errors due to https://github.com/JuliaLang/julia/issues/51325
@test Base.isexported(@__MODULE__, :foo_50105) === false
VERSION >= v"1.11.0-DEV.469" && @test Base.ispublic(@__MODULE__, :foo_50105)
@test Base.isexported(Mod50105, :bar) === false
VERSION >= v"1.11.0-DEV.469" && @test Base.ispublic(Mod50105, :bar)

@test_throws LoadError @eval @public 4, bar
@test_throws LoadError @eval @public foo bar
end
Loading