Docstring being replaced

I make the following module:

module Foo

export Bar

"""
    Bar

Struct bar docstring.

"""
struct Bar
    n::Int

    @doc """
        Bar(n::Int)

    Constructor docstring.

    """
    function Bar(n::Int)
        return new(n)
    end
end

end

When I ask for the documentation of Bar in the REPL, I get both the docstring for the struct as well as that for the constructor.

Now, if I overload function call by adding:

"""
    (b::Bar)(x::Int)

Do something.

"""
function (b::Bar)(x::Int)
    return b.n + x
end

then when I do using Foo I get a warning: Replacing docs for Foo.Bar :: Tuple{Int64} in module Foo. The docstring for the constructor is then replaced by the docstring for the function call operator.

How can I keep both docstrings?

1 Like