Skip to content

Commit 9de856b

Browse files
Merge pull request #131 from JuliaDocs/mh/pr-127
Fix extraction of argnames for generated functions (cherry-picked)
2 parents 9a8adb5 + 5fcd6f7 commit 9de856b

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/utilities.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,18 @@ args = arguments(first(methods(f)))
449449
```
450450
"""
451451
function arguments(m::Method)
452-
local template = get_method_source(m)
453-
if isdefined(template, :slotnames)
454-
local args = map(template.slotnames[1:nargs(m)]) do arg
452+
local argnames = nothing
453+
if isdefined(m, :generator)
454+
# Generated function.
455+
argnames = m.generator.argnames
456+
else
457+
local template = get_method_source(m)
458+
if isdefined(template, :slotnames)
459+
argnames = template.slotnames
460+
end
461+
end
462+
if argnames !== nothing
463+
local args = map(argnames[1:nargs(m)]) do arg
455464
arg === Symbol("#unused#") ? "_" : arg
456465
end
457466
return filter(arg -> arg !== Symbol("#self#"), args)

test/TestModule/M.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ h_2(x::A{Int}) = x
1515
h_3(x::A{T}) where {T} = x
1616
h_4(x, ::Int, z) = x
1717

18+
@generated g_1(x) = x
19+
@generated g_2(x::String) = x
20+
1821
i_1(x; y = x) = x * y
1922
i_2(x::Int; y = x) = x * y
2023
i_3(x::T; y = x) where {T} = x * y

test/tests.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ end
166166
@test occursin("\ng(x, y, z; kwargs...)\n", str)
167167
@test occursin("\n```\n", str)
168168

169+
doc.data = Dict(
170+
:binding => Docs.Binding(M, :g_1),
171+
:typesig => Tuple{Any},
172+
:module => M,
173+
)
174+
DSE.format(SIGNATURES, buf, doc)
175+
str = String(take!(buf))
176+
@test occursin("\n```julia\n", str)
177+
@test occursin("\ng_1(x)\n", str)
178+
@test occursin("\n```\n", str)
179+
169180
doc.data = Dict(
170181
:binding => Docs.Binding(M, :h_4),
171182
:typesig => Union{Tuple{Any, Int, Any}},
@@ -196,6 +207,16 @@ end
196207
end
197208
@test occursin("\n```\n", str)
198209

210+
doc.data = Dict(
211+
:binding => Docs.Binding(M, :g_2),
212+
:typesig => Tuple{String},
213+
:module => M,
214+
)
215+
DSE.format(TYPEDSIGNATURES, buf, doc)
216+
str = String(take!(buf))
217+
@test occursin("\n```julia\n", str)
218+
@test occursin("\ng_2(x::String)", str)
219+
@test occursin("\n```\n", str)
199220

200221
doc.data = Dict(
201222
:binding => Docs.Binding(M, :h),

0 commit comments

Comments
 (0)