Skip to content

Commit 5092379

Browse files
authored
document the return types of fieldname and fieldnames (#55259)
1 parent 0f51a63 commit 5092379

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

base/reflection.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,18 @@ end
212212
213213
Get the name of field `i` of a `DataType`.
214214
215+
The return type is `Symbol`, except when `x <: Tuple`, in which case the index of the field is returned, of type `Int`.
216+
215217
# Examples
216218
```jldoctest
217219
julia> fieldname(Rational, 1)
218220
:num
219221
220222
julia> fieldname(Rational, 2)
221223
:den
224+
225+
julia> fieldname(Tuple{String,Int}, 2)
226+
2
222227
```
223228
"""
224229
function fieldname(t::DataType, i::Integer)
@@ -246,6 +251,9 @@ fieldname(t::Type{<:Tuple}, i::Integer) =
246251
247252
Get a tuple with the names of the fields of a `DataType`.
248253
254+
Each name is a `Symbol`, except when `x <: Tuple`, in which case each name (actually the
255+
index of the field) is an `Int`.
256+
249257
See also [`propertynames`](@ref), [`hasfield`](@ref).
250258
251259
# Examples
@@ -255,6 +263,9 @@ julia> fieldnames(Rational)
255263
256264
julia> fieldnames(typeof(1+im))
257265
(:re, :im)
266+
267+
julia> fieldnames(Tuple{String,Int})
268+
(1, 2)
258269
```
259270
"""
260271
fieldnames(t::DataType) = (fieldcount(t); # error check to make sure type is specific enough

0 commit comments

Comments
 (0)