Hi,
Believe I am running into a bit of a bug / unexpected behaviour that I can’t seem to work around when extracting an interface into a concrete type having defined more than one in a module.
e.g.: this works:
using StructTypes, Parameters, JSON3
abstract type ICompute end
StructTypes.StructType(::Type{ICompute}) = StructTypes.AbstractType()
StructTypes.subtypekey(::Type{ICompute}) = :computeName
function StructTypes.subtypes(::Type{ICompute})
(
percentile = Percentile
)
end
struct Percentile <: ICompute
computeName
id
percentiles :: Vector{Float64}
end
StructTypes.StructType(::Type{Percentile}) = StructTypes.Struct()
percentile = JSON3.read("""
{
"computeName": "percentile",
"id": "1",
"percentiles": [10,20,30]
}""", ICompute)
works, but trying to extend it to include more abstract types:
using StructTypes, Parameters, JSON3
abstract type ICompute end
StructTypes.StructType(::Type{ICompute}) = StructTypes.AbstractType()
StructTypes.subtypekey(::Type{ICompute}) = :computeName
function StructTypes.subtypes(::Type{ICompute})
(
percentile = Percentile
)
end
struct Percentile <: ICompute
computeName
id
percentiles :: Vector{Float64}
end
StructTypes.StructType(::Type{Percentile}) = StructTypes.Struct()
abstract type IQuery end
StructTypes.StructType(::Type{IQuery}) = StructTypes.AbstractType()
StructTypes.subtypekey(::Type{IQuery}) = :queryName
function StructTypes.subtypes(::Type{IQuery})
(
dataDominance = DataDominance
)
end
struct DataDominance <: IQuery
queryName
id
percentiles :: Vector{Float64}
end
StructTypes.StructType(::Type{DataDominance}) = StructTypes.Struct()
percentile = JSON3.read("""
{
"computeName": "percentile",
"id": "1",
"percentiles": [10,20,30]
}""", ICompute)
datadominance = JSON3.read("""
{
"queryName": "dataDominance",
"id": "1",
"percentiles": [10,20,30]
}""", IQuery)
fails with error:
ERROR: LoadError: MethodError: no method matching length(::Type{Main.GetMetricModels.DataDominance})
Closest candidates are:
length(!Matched::Union{Base.KeySet, Base.ValueIterator}) at abstractdict.jl:58
length(!Matched::Union{LinearAlgebra.Adjoint{T, S}, LinearAlgebra.Transpose{T, S}} where {T, S}) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\adjtrans.jl:195
length(!Matched::Union{DataStructures.OrderedRobinDict, DataStructures.RobinDict}) at C:\Users\doliver\.julia\packages\DataStructures\ixwFs\src\ordered_robin_dict.jl:86
version info:
Packages info:
Would someone mind trying to run the above and feeding back - I’ve tried myriad combinations and just not been successful.
Regards,