Skip to content

Commit 4a43b03

Browse files
fix hasfield for unionall-wrapped DataTypes (#36694)
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
1 parent d9b7d7e commit 4a43b03

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

base/reflection.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ function fieldindex(T::DataType, name::Symbol, err::Bool=true)
635635
return Int(ccall(:jl_field_index, Cint, (Any, Any, Cint), T, name, err)+1)
636636
end
637637

638+
fieldindex(t::UnionAll, name::Symbol, err::Bool=true) = fieldindex(something(argument_datatype(t)), name, err)
639+
638640
argument_datatype(@nospecialize t) = ccall(:jl_argument_datatype, Any, (Any,), t)
639641

640642
"""

test/reflection.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ tlayout = TLayout(5,7,11)
225225
@test fieldnames(TLayout) == (:x, :y, :z) == Base.propertynames(tlayout)
226226
@test hasfield(TLayout, :y)
227227
@test !hasfield(TLayout, :a)
228+
@test hasfield(Complex, :re)
229+
@test !hasfield(Complex, :qxq)
228230
@test hasproperty(tlayout, :x)
229231
@test !hasproperty(tlayout, :p)
230232
@test [(fieldoffset(TLayout,i), fieldname(TLayout,i), fieldtype(TLayout,i)) for i = 1:fieldcount(TLayout)] ==

0 commit comments

Comments
 (0)