Skip to content

Commit

Permalink
fix docing call overloads (JuliaLang#25626)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored and JeffBezanson committed Jan 18, 2018
1 parent 11cbc4d commit 71173e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ namify(x) = nameof(x, isexpr(x, :macro))
function nameof(x::Expr, ismacro)
if isexpr(x, :.)
ismacro ? macroname(x) : x
# Call overloading, e.g. `(a::A)(b) = b` or `function (a::A)(b) b end` should document `A(b)`
elseif (isexpr(x, :function) || isexpr(x, :(=))) && isexpr(x.args[1], :call) && isexpr(x.args[1].args[1], :(::))
return nameof(x.args[1].args[1].args[2], ismacro)
else
n = isexpr(x, (:module, :struct)) ? 2 : 1
nameof(x.args[n], ismacro)
Expand Down
27 changes: 27 additions & 0 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1092,3 +1092,30 @@ end
struct t_docs_abc end
@test "t_docs_abc" in Docs.accessible(@__MODULE__)

# Call overloading issue #20087
"""
Docs for `MyFunc` struct.
"""
mutable struct MyFunc
x
end

"""
Docs for calling `f::MyFunc`.
"""
function (f::MyFunc)(x)
f.x = x
return f
end

@test docstrings_equal(@doc(MyFunc(2)),
doc"""
Docs for calling `f::MyFunc`.
""")

struct A_20087 end

"""a"""
(a::A_20087)() = a

@test docstrings_equal(@doc(A_20087()), doc"a")

0 comments on commit 71173e4

Please sign in to comment.