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

TYPEDSIGNATURES error with @generated functions #157

Open
tomerarnon opened this issue Oct 5, 2023 · 3 comments
Open

TYPEDSIGNATURES error with @generated functions #157

tomerarnon opened this issue Oct 5, 2023 · 3 comments

Comments

@tomerarnon
Copy link

tomerarnon commented Oct 5, 2023

This happens whether the function is @generated, or defined with if @generated ... method.

julia> using DocStringExtensions

julia> begin
       """
           $TYPEDSIGNATURES
       example
       """
       @generated function example(x)
           :(return x)
       end
       end
example

help?> example
search: example

ERROR: BoundsError: attempt to access Core.SimpleVector at index [2]
Stacktrace:
  [1] getindex
    @ ./essentials.jl:697 [inlined]
  [2] may_invoke_generator(method::Method, atype::Any, sparams::Core.SimpleVector)
    @ Base ./reflection.jl:1166
  [3] func_for_method_checked
    @ ./reflection.jl:1188 [inlined]
  [4] return_types(f::Any, types::Any; world::UInt64, interp::Core.Compiler.NativeInterpreter)
    @ Base ./reflection.jl:1415
  [5] return_types
    @ ./reflection.jl:1398 [inlined]
  [6] printmethod(buffer::IOBuffer, binding::Base.Docs.Binding, func::Function, method::Method, typesig::Type)
    @ DocStringExtensions ~/.julia/packages/DocStringExtensions/JVu77/src/utilities.jl:363
  [7] format(#unused#::DocStringExtensions.TypedMethodSignatures, buf::IOBuffer, doc::Base.Docs.DocStr)
    @ DocStringExtensions ~/.julia/packages/DocStringExtensions/JVu77/src/abbreviations.jl:398
  [8] formatdoc(buf::IOBuffer, doc::Base.Docs.DocStr, part::DocStringExtensions.TypedMethodSignatures)
    @ DocStringExtensions ~/.julia/packages/DocStringExtensions/JVu77/src/abbreviations.jl:25
  [9] formatdoc(d::Base.Docs.DocStr)
    @ REPL /Applications/Julia-1.9.2.app/Contents/Resources/julia/share/julia/stdlib/v1.9/REPL/src/docview.jl:88
 [10] parsedoc(d::Base.Docs.DocStr)
    @ REPL /Applications/Julia-1.9.2.app/Contents/Resources/julia/share/julia/stdlib/v1.9/REPL/src/docview.jl:96
 [11] map!(f::typeof(Base.Docs.parsedoc), dest::Vector{Any}, A::Vector{Base.Docs.DocStr})
    @ Base ./abstractarray.jl:3254
 [12] mapany(f::Function, A::Vector{Base.Docs.DocStr})
    @ Base ./abstractarray.jl:3263
 [13] doc(binding::Base.Docs.Binding, sig::Type)
    @ REPL /Applications/Julia-1.9.2.app/Contents/Resources/julia/share/julia/stdlib/v1.9/REPL/src/docview.jl:193
 [14] doc(binding::Base.Docs.Binding)
    @ REPL /Applications/Julia-1.9.2.app/Contents/Resources/julia/share/julia/stdlib/v1.9/REPL/src/docview.jl:160
 [15] top-level scope
    @ /Applications/Julia-1.9.2.app/Contents/Resources/julia/share/julia/stdlib/v1.9/REPL/src/docview.jl:481

SIGNATURES is fine:


julia> begin
       """    
           $SIGNATURES
       example
       """
       @generated function example(x)
           :(return x)
       end
       end
example

help?> example
search: example

  example(x)
  

  example

In my real example, this is happening because I have a template which splices $TYPEDSIGNATURES for all methods. I would indeed like to show the type annotation of the generated function if possible.

@MichaelHatherly
Copy link
Member

Looks like this is failing in Base.return_types. What happens if you instead of documenting the generated function directly wrap it in an "outer" function like so:

@generated function _example(x)
    :(return x)
end

"""
    $TYPEDSIGNATURES

example
"""
example(x) = _example(x)

Slightly more indirection, I know, but might be a solution until the bug can be fixed.

@tomerarnon
Copy link
Author

That indirection does circumvent the error, thanks!

@MichaelHatherly
Copy link
Member

Great, we'll leave this open as a hint to future users, and a reminder to work out some kind of fix if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants