Skip to content

Commit

Permalink
Allow documenting methods with return types
Browse files Browse the repository at this point in the history
E.g.

    "..."
    f{T}(x::T)::T = x

Fixes problem mentioned in

    JuliaLang#16432 (comment)
  • Loading branch information
MichaelHatherly authored and JeffBezanson committed May 31, 2016
1 parent 37c8c84 commit 1fc6bbc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ isquotedmacrocall(x) =
isexpr(x.args[1].value, :macrocall, 1)
# Simple expressions / atoms the may be documented.
isbasicdoc(x) = isexpr(x, :.) || isa(x, Union{QuoteNode, Symbol})
is_signature(x) = isexpr(x, :call) || (isexpr(x, :(::), 2) && isexpr(x.args[1], :call))

function docm(meta, ex, define = true)
# Some documented expressions may be decorated with macro calls which obscure the actual
Expand All @@ -621,7 +622,7 @@ function docm(meta, ex, define = true)
# function f end
# f(...)
#
isexpr(x, FUNC_HEADS) && isexpr(x.args[1], :call) ? objectdoc(meta, def, x, signature(x)) :
isexpr(x, FUNC_HEADS) && is_signature(x.args[1]) ? objectdoc(meta, def, x, signature(x)) :
isexpr(x, :function) && !isexpr(x.args[1], :call) ? objectdoc(meta, def, x) :
isexpr(x, :call) ? calldoc(meta, x) :

Expand Down
13 changes: 13 additions & 0 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ const val = Foo(1.0)
function multidoc end,
function multidoc! end

"returntype-1"
returntype(x::Float64)::Float64 = x

"returntype-2"
function returntype(x::Int)::Int
x
end

end

let md = meta(DocsTest)[@var(DocsTest)]
Expand Down Expand Up @@ -223,6 +231,11 @@ let IT = @var(DocsTest.IT)
@test d.data[:fields][:y] == "IT.y"
end

let rt = @var(DocsTest.returntype)
md = meta(DocsTest)[rt]
@test md.order == [Tuple{Float64}, Tuple{Int}]
end

@test docstrings_equal(@doc(DocsTest.TA), doc"TA")

@test docstrings_equal(@doc(DocsTest.@mac), doc"@mac()")
Expand Down

0 comments on commit 1fc6bbc

Please sign in to comment.