Hi,
I’m passing a dict to a constructor containing objects which are a subtype of the type expected and I get a type error on it:
ERROR: TypeError: in keyword argument res_input, expected Dict{BluePrint,Int64}, got a value of type Dict{ConsumableBluePrint,Int64}
ConsumableBluePrint is a subtype of BluePrint though.
abstract type Entity end
abstract type BluePrint end
struct ConsumableBluePrint <: BluePrint
type_id::UUID
name::String
ConsumableBluePrint(name::String) = new(uuid4(), name)
end
struct ToolBluePrint <: BluePrint
type_id::UUID
name::String
lifecycle::Restorable
ToolBluePrint(name::String, lifecycle::Restorable = Restorable()) =
new(uuid4(), name, lifecycle)
end
struct ProducerBluePrint <: BluePrint
type_id::UUID
name::String
lifecycle::Restorable
res_input::Dict{BluePrint,Int64} # Required input per batch
output::Dict{BluePrint,Int64} # Output per batch. The BluePrint and the number of items per BluePrint.
max_batches::Int64
ProducerBluePrint(
name::String,
lifecycle::Restorable = Restorable();
res_input = Dict(),
output = Dict(),
max_batches::Int = 1,
) = new(uuid4(), name, lifecycle, res_input, output, max_batches)
end
So, why do I get this error? And how can I fix it?
Thanks in advance,
Stef