Documenter.jl icon indicating copy to clipboard operation
Documenter.jl copied to clipboard

Docstrings for some callable objects in @autodocs error

Open jlapeyre opened this issue 7 years ago • 12 comments

julia --color=yes make.jl fails with an error:

ERROR: LoadError: UndefVarError: cdf not defined

My module does include parameters and local variables here and there named cdf.

The stack trace includes no information on which line or file or directory or function, etc. is causing the error. So, it is not possible to debug this, at least directly. I searched the Documenter docs for "debug", but could not find anything. I did find a debug=false option for makedocs in a repo, so I tried debug=true. This did not change anything.

Julia v0.6.2

jlapeyre avatar May 20 '18 20:05 jlapeyre

Is it a public package? If so, do you have a link to the repo?

fredrikekre avatar May 20 '18 20:05 fredrikekre

Yes. I just discovered the problem. Here is the offending line.

It is a doc string for a callable object. I read another issue about Documenter (or tool it uses) failing with some Julia syntax, which made me think of removing that doc string. But, I don't understand why nothing useful appeared in the stack trace. Unless I'm mistaken, this is not the case in general.

Btw. Here is the error:

ERROR: LoadError: UndefVarError: cdf not defined
Stacktrace:
 [1] category(::Base.Docs.Binding) at /home/lapeyre/.julia/v0.6/Documenter/src/DocSystem.jl:262
 [2] runner(::Type{Documenter.Expanders.AutoDocsBlocks}, ::Base.Markdown.Code, ::Documenter.Documents.Page, ::Documenter.Documents.Document) at /home/lapeyre/.julia/v0.6/Documenter/src/Expanders.jl:356
 [3] dispatch(::Type{Documenter.Expanders.ExpanderPipeline}, ::Base.Markdown.Code, ::Vararg{Any,N} where N) at /home/lapeyre/.julia/v0.6/Documenter/src/Selectors.jl:168
 [4] expand(::Documenter.Documents.Document) at /home/lapeyre/.julia/v0.6/Documenter/src/Expanders.jl:31
 [5] runner(::Type{Documenter.Builder.ExpandTemplates}, ::Documenter.Documents.Document) at /home/lapeyre/.julia/v0.6/Documenter/src/Builder.jl:178
 [6] dispatch(::Type{Documenter.Builder.DocumentPipeline}, ::Documenter.Documents.Document, ::Vararg{Documenter.Documents.Document,N} where N) at /home/lapeyre/.julia/v0.6/Documenter/src/Selectors.jl:168
 [7] cd(::Documenter.##2#3{Documenter.Documents.Document}, ::String) at ./file.jl:70
 [8] #makedocs#1(::Bool, ::Array{Any,1}, ::Function) at /home/lapeyre/.julia/v0.6/Documenter/src/Documenter.jl:204
 [9] (::Documenter.#kw##makedocs)(::Array{Any,1}, ::Documenter.#makedocs) at ./<missing>:0
 [10] include_from_node1(::String) at ./loading.jl:576
 [11] include(::String) at ./sysimg.jl:14
 [12] process_options(::Base.JLOptions) at ./client.jl:305
 [13] _start() at ./client.jl:371
while loading /home/lapeyre/.julia/v0.6/EmpiricalCDFs/docs/make.jl, in expression starting on line 3

jlapeyre avatar May 20 '18 20:05 jlapeyre

... I have no idea where Julia sticks that doc string. Arguably, that documentation should be part of a different doc string, maybe for the type itself.

EDIT: I see a note to myself # This documentation is inaccesible ?. So I think the particular error is mine.

jlapeyre avatar May 20 '18 20:05 jlapeyre

I don't see any @autodocs blocks in the repo.

fredrikekre avatar May 21 '18 06:05 fredrikekre

There is also no cdf function, so I wonder why @autodocs would try to include that?

fredrikekre avatar May 21 '18 06:05 fredrikekre

Sorry, I did not see the email ping. I never pushed the version with @autodocs. There is no cdf function, but I define a method to make EmpiricalCDF a callable type.

The error occured when I did this:

"""
    (cdf::EmpiricalCDF)(x::Real) = _val_at_index(cdf, getcdfindex(cdf, x))
blahblah
"""
(cdf::EmpiricalCDF)(x::Real) = _val_at_index(cdf, getcdfindex(cdf, x))

jlapeyre avatar May 21 '18 15:05 jlapeyre

Ok, repro here: TestPackage.jl

module TestPackage
struct Foo end
"""
Callable Foo.
"""
(foo::Foo)() = println("Hello")
end

with index.md

Modules = [TestPackage, ]

fredrikekre avatar May 21 '18 15:05 fredrikekre

I believe the callable object syntax is not properly supported, since most of the logic was written in the 0.4 era (where this stuff was done with Base.call?).

mortenpi avatar May 21 '18 22:05 mortenpi

I guess I'm also experiencing this error.

It seems that

(p::EpsilonGreedySelector)(values::AbstractArray{T, 1}) where T = println("!")

will throw error. But the following one won't:

(p::EpsilonGreedySelector)(values::AbstractArray{<:Number, 1}) =  println("!")

Hope it is helpful to debug.

findmyway avatar Jan 20 '19 05:01 findmyway

Based in the repro by @fredrikekre, this seems to have been fixed. I haven't been able to reproduce this? image

Julia 1.6 Documenter v0.26.3

Sov-trotter avatar May 06 '21 15:05 Sov-trotter

as previously suggested by @findmyway, this only seems to happen for parametric callables with a where. While @fredrikekre​'s example runs fine for me (Julia 1.6.2, Documenter 0.27.5), modifying the relevant lines to

struct Foo{T} end
"""
Callable Foo.
"""
(foo::Foo{T})() where {T} = println("Hello")

breaks things (with ERROR: LoadError: UndefVarError: foo not defined)

lhupe avatar Sep 06 '21 12:09 lhupe

Probably related to https://github.com/JuliaDocs/Documenter.jl/issues/558

odow avatar Nov 01 '23 21:11 odow