Skip to content

Named tuples not converting #72

@zot

Description

@zot

Hi, I'm getting this error trying to convert a NamedTuple to store in a NamedTuple field:

ERROR: ArgumentError: type does not have a definite number of fields
Stacktrace:
  [1] fieldcount(t::Any)
    @ Base ./reflection.jl:729
  [2] construct
    @ ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:573 [inlined]
  [3] constructfrom(#unused#::StructTypes.UnorderedStruct, #unused#::Type{NamedTuple}, #unused#::StructTypes.UnorderedStruct, obj::NamedTuple{(), Tuple{}})
    @ StructTypes ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:1046
  [4] constructfrom
    @ ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:1018 [inlined]
  [5] constructfrom(#unused#::Type{NamedTuple}, obj::NamedTuple{(), Tuple{}})
    @ StructTypes ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:905
  [6] StructClosure
    @ ~/.julia/packages/StructTypes/Cmlkm/src/StructTypes.jl:1041 [inlined]

I made some definitions that seem to fix it, what do you think (seems like both Struct and UnorderedStruct are needed)?

constructfrom(::Struct, ::Type{ST}, ::Struct, obj::OT) where {ST <: NamedTuple, OT <: ST} = obj
constructfrom(::UnorderedStruct, ::Type{ST}, ::UnorderedStruct, obj::OT) where {ST <: NamedTuple, OT <: ST} = obj

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions