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

Fallback to getproperty in at-doc #30835

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion base/docs/bindings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ struct Binding
end
end

bindingexpr(x) = Expr(:call, Binding, splitexpr(x)...)
binding(m::Module, v::Symbol) = Binding(m, v)
binding(x, v) = getproperty(x, v)
bindingexpr(x) = Expr(:call, binding, splitexpr(x)...)

defined(b::Binding) = isdefined(b.mod, b.var)
resolve(b::Binding) = getfield(b.mod, b.var)
Expand Down
26 changes: 14 additions & 12 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -890,65 +890,67 @@ end

# Bindings.

import Base.Docs: @var, Binding, defined
import Base.Docs: @var, binding, defined

let x = Binding(Base, Symbol("@time"))
let x = binding(Base, Symbol("@time"))
@test defined(x) == true
@test @var(@time) == x
@test @var(Base.@time) == x
@test @var(Base.Iterators.@time) == x
end

let x = Binding(Iterators, :enumerate)
let x = binding(Iterators, :enumerate)
@test defined(x) == true
@test @var(enumerate) == x
@test @var(Base.enumerate) == x
@test @var(Iterators.enumerate) == x
@test @var(Base.Iterators.enumerate) == x
end

let x = Binding(Core, :Int)
let x = binding(Core, :Int)
@test defined(x) == true
@test @var(Int) == x
@test @var(Base.Int) == x
@test @var(Core.Int) == x
end

let x = Binding(Base, :Iterators)
let x = binding(Base, :Iterators)
@test defined(x) == true
@test @var(Iterators) == x
@test @var(Base.Iterators) == x
@test @var(Main.Iterators) == x
end

let x = Binding(Base, :VERSION)
let x = binding(Base, :VERSION)
@test defined(x) == true
@test @var(VERSION) == x
@test @var(Base.VERSION) == x
end

let x = Binding(Base, :bindingdoesnotexist)
let x = binding(Base, :bindingdoesnotexist)
@test defined(x) == false
@test @var(Base.bindingdoesnotexist) == x
end

let x = Binding(curmod, :bindingdoesnotexist)
let x = binding(curmod, :bindingdoesnotexist)
@test defined(x) == false
@test @var(bindingdoesnotexist) == x
end

let x = Binding(Main, :+)
let x = binding(Main, :+)
@test Meta.parse(string(x)) == :(Base.:+)
end

let x = Binding(Meta, :parse)
let x = binding(Meta, :parse)
@test Meta.parse(string(x)) == :(Base.Meta.parse)
end

let x = Binding(Main, :⊕)
let x = binding(Main, :⊕)
@test Meta.parse(string(x)) == :(⊕)
end

@test binding(Some(123), :value) == 123

doc_util_path = Symbol(joinpath("docs", "utils.jl"))

@test sprint(repl_latex, "√") == "\"√\" can be typed by \\sqrt<tab>\n\n"
Expand Down Expand Up @@ -1072,7 +1074,7 @@ let foo_docs = meta(I22105)[@var(I22105.foo)].docs
@test docstr.data[:linenumber] == I22105.lineno + 1
@test docstr.data[:module] === I22105
@test docstr.data[:typesig] === Union{}
@test docstr.data[:binding] == Binding(I22105, :foo)
@test docstr.data[:binding] == binding(I22105, :foo)
end

# issue #23011
Expand Down