pmc4
February 18, 2026, 1:46pm
1
Hello, everyone. While I was adding some docstrings to a mutable struct, I’ve realized that when the field is set as constant, the documentation doesn’t work. Take, for example, the following mutable struct:
"Some random docs I write here."
mutable struct Foo{T<:AbstractFloat}
"Mass"
const m::T
"Time"
t::T
end
If I enter into help mode and type Foo, I get the corresponding docstring:
help?> Foo
search: Foo Bool
Some random docs I write here.
The same happens with the field t:
help?> Foo.t
Time
However, when I search for the constant field, nothing shows up. As if that field didn’t have docstrings:
Foo.m
Foo has fields m, and t.
Is this a bug? I’ve read the corresponding section at the docs but nothing is mentioned. Writing @doc in front of the string does not work either.
2 Likes
nsajko
February 19, 2026, 5:20am
2
Known issue:
opened 02:29PM - 26 Jun 25 UTC
docsystem
`const` fields of mutable structs cannot be annotated with docstrings in the sam… e way as mutable fields, e.g.
```julia
"a struct docstring"
mutable struct SomeStruct
"a field docstring"
mutablefield
"another field docstring"
const constfield
end
```
results in the following behaviour (tested on v1.11.5 and 1.12.0-beta4)
```
help?> SomeStruct.mutablefield
a field docstring
help?> SomeStruct.constfield
SomeStruct has fields mutablefield, and constfield.
```
This issue has already been filed with DocStringExtensions (https://github.com/JuliaDocs/DocStringExtensions.jl/issues/155) back in September '24, but it's definitely a Julia problem and I can't find any previous issues here.
Some other known issues with field doc strings:
opened 04:15PM - 19 Jun 18 UTC
docsystem
Consider (on 0.7 and 0.6)
```
julia> "Doc" struct A{T}
"field"
… a
end
A
help?> A
search: A Any ANY any all abs ARGS ans axes atan asin asec any! all! acsc acot acos abs2 Array atanh atand atan2 asinh asind asech asecd ascii angle acsch acscd acoth
Doc
help?> A.a
ERROR: MethodError: no method matching Base.Docs.Binding(::Type{A}, ::Symbol)
Closest candidates are:
Base.Docs.Binding(::Module, ::Symbol) at docs/bindings.jl:12
Stacktrace:
[1] top-level scope at /home/mauro/julia/julia-master/usr/share/julia/stdlib/v0.7/REPL/src/docview.jl:306
help?> A{Int}.a
ERROR: MethodError: no method matching Base.Docs.Binding(::Type{A{Int64}}, ::Symbol)
Closest candidates are:
Base.Docs.Binding(::Module, ::Symbol) at docs/bindings.jl:12
julia> const AA = A{Int} # work-around
A{Int64}
help?> AA.a
field
```
opened 06:15PM - 04 Sep 23 UTC
bug
REPL
docsystem
I don't really see a pattern of when the REPL provides useful hints on this sort… of field access and when it throws what appears to be an internal error:
```julia
julia> module M
struct T
"a field with a docstring"
my_field
end
const C = T
f() = T
end
WARNING: replacing module M.
Main.M
help?> M.T.field
Main.M.T has fields my_field.
help?> M.C.field
Main.M.T has fields my_field.
help?> M.f().field
ERROR: MethodError: no method matching Base.Docs.Binding(::Type{Main.M.T}, ::Symbol)
Closest candidates are:
Base.Docs.Binding(::Module, ::Symbol)
@ Base docs/bindings.jl:9
Stacktrace:
[1] top-level scope
@ none:1
help?> M.T(1).field
ERROR: MethodError: no method matching Base.Docs.Binding(::Main.M.T, ::Symbol)
Closest candidates are:
Base.Docs.Binding(::Module, ::Symbol)
@ Base docs/bindings.jl:9
Stacktrace:
[1] top-level scope
@ none:1
help?> M.T(1).my_field
ERROR: MethodError: no method matching Base.Docs.Binding(::Main.M.T, ::Symbol)
Closest candidates are:
Base.Docs.Binding(::Module, ::Symbol)
@ Base docs/bindings.jl:9
Stacktrace:
[1] top-level scope
@ none:1
julia> x = M.T(1)
Main.M.T(1)
help?> x.field
ERROR: MethodError: no method matching Base.Docs.Binding(::Main.M.T, ::Symbol)
Closest candidates are:
Base.Docs.Binding(::Module, ::Symbol)
@ Base docs/bindings.jl:9
Stacktrace:
[1] top-level scope
@ ~/.julia/juliaup/julia-1.10.0-beta2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/REPL/src/docview.jl:558
```
1 Like
pmc4
February 19, 2026, 12:19pm
3
nsajko:
Known issue:
Thanks! Good to know, I was getting confused trying to understand what I was doing wrong.
1 Like