Skip to content

Commit 90d346f

Browse files
authored
fix help?> StructType.field command (JuliaLang#57107)
`help?> StructType.field` currently errors when `StructType` doesn't have any field documentation at all. This commit adds a proper guard against such cases.
1 parent 2e6ffbc commit 90d346f

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

stdlib/REPL/src/docview.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,17 @@ function fielddoc(binding::Binding, field::Symbol)
662662
for mod in modules
663663
dict = meta(mod; autoinit=false)
664664
isnothing(dict) && continue
665-
if haskey(dict, binding)
666-
multidoc = dict[binding]
667-
if haskey(multidoc.docs, Union{})
668-
fields = multidoc.docs[Union{}].data[:fields]
669-
if haskey(fields, field)
670-
doc = fields[field]
671-
return isa(doc, Markdown.MD) ? doc : Markdown.parse(doc)
665+
multidoc = get(dict, binding, nothing)
666+
if multidoc !== nothing
667+
structdoc = get(multidoc.docs, Union{}, nothing)
668+
if structdoc !== nothing
669+
fieldsdoc = get(structdoc.data, :fields, nothing)
670+
if fieldsdoc !== nothing
671+
fielddoc = get(fieldsdoc, field, nothing)
672+
if fielddoc !== nothing
673+
return isa(fielddoc, Markdown.MD) ?
674+
fielddoc : Markdown.parse(fielddoc)
675+
end
672676
end
673677
end
674678
end

stdlib/REPL/test/docview.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ end
9292
@test endswith(get_help_standard("StructWithOneField.not_a_field"), "StructWithOneField` has field `field1`.\n")
9393
@test endswith(get_help_standard("StructWithTwoFields.not_a_field"), "StructWithTwoFields` has fields `field1`, and `field2`.\n")
9494
@test endswith(get_help_standard("StructWithThreeFields.not_a_field"), "StructWithThreeFields` has fields `field1`, `field2`, and `field3`.\n")
95+
96+
# Shouldn't error if the struct doesn't have any field documentations at all.
97+
@test endswith(get_help_standard("Int.not_a_field"), "`$Int` has no fields.\n")
9598
end
9699

97100
module InternalWarningsTests

0 commit comments

Comments
 (0)