Skip to content

Commit 47908c8

Browse files
authored
fix getting field docstrings for parametric structs (#59725)
1 parent 18b5ff6 commit 47908c8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

stdlib/REPL/src/docview.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ function _repl(x, brief::Bool=true, mod::Module=Main, internal_accesses::Union{N
640640
docs = esc(:(@doc $x))
641641
docs = if isfield(x)
642642
quote
643-
if isa($(esc(x.args[1])), DataType)
643+
if $(esc(x.args[1])) isa Type
644644
fielddoc($(esc(x.args[1])), $(esc(x.args[2])))
645645
else
646646
$docs
@@ -684,6 +684,7 @@ function fielddoc(binding::Binding, field::Symbol)
684684
end
685685

686686
# As with the additional `doc` methods, this converts an object to a `Binding` first.
687+
fielddoc(obj::UnionAll, field::Symbol) = fielddoc(Base.unwrap_unionall(obj), field)
687688
fielddoc(object, field::Symbol) = fielddoc(aliasof(object, typeof(object)), field)
688689

689690

stdlib/REPL/test/docview.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ end
111111
@test endswith(get_help_standard("Int.not_a_field"), "`$Int` has no fields.\n")
112112
end
113113

114+
@testset "Parametric struct field help (#59524)" begin
115+
"NonParametricStruct docstring"
116+
struct NonParametricStruct
117+
"field_x docstring"
118+
field_x::Float64
119+
end
120+
121+
"ParametricStruct docstring"
122+
struct ParametricStruct{T<:Real}
123+
"field_y docstring"
124+
field_y::T
125+
end
126+
127+
@test occursin("field_x docstring", get_help_standard("NonParametricStruct.field_x"))
128+
@test occursin("field_y docstring", get_help_standard("ParametricStruct.field_y"))
129+
@test endswith(get_help_standard("ParametricStruct.not_a_field"), "ParametricStruct` has field `field_y`.\n")
130+
end
131+
114132
module InternalWarningsTests
115133

116134
module A

0 commit comments

Comments
 (0)