JuliaDocs / JuliaDocs/DocStringExtensions.jl

TYPEDSIGNATURES error with @generated functions

Open
#157 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
126
Forks
35
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example with TYPEDSIGNATURES and compare it with SIGNATURES, using the Julia 1.9.2 behavior shown. Start in src/utilities.jl at printmethod and src/abbreviations.jl at TypedMethodSignatures; done means generated functions no longer trigger the BoundsError and their typed signature is handled as requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.