Weird constructor error

Hi,

I’m getting an error when calling a constructor and I can’t figure out what’s wrong. It used to work but after fiddling with the code a bit (I honestly don’t know what I changed exactly anymore since I was experimenting) I now get the following error:

ProductBlueprint("P")
ERROR: MethodError: no method matching (::Main.Production.var"#ProductBlueprint#3#4")(::Dict{Blueprint,Int64}, ::Int64, ::Type{ProductBlueprint}, ::String, ::Restorable)
Closest candidates are:
  ProductBlueprint#3(::Dict{Blueprint,Int64}, ::Float64, ::Type{ProductBlueprint}, ::Any, ::Any) at /Users/stef/Programming/Julia Projects/loreco-abm/cockpit/production/entities.jl:31
Stacktrace:
 [1] ProductBlueprint(::String, ::Restorable) at /Users/stef/Programming/Julia Projects/loreco-abm/cockpit/production/entities.jl:31 (repeats 2 times)
 [2] top-level scope at none:1

The source code:

abstract type Blueprint end

struct ConsumableBlueprint <: Blueprint
    type_id::UUID
    name::String
    ConsumableBlueprint(name) = new(uuid4(), name)
end

struct ProductBlueprint <: Blueprint
    type_id::UUID
    name::String
    lifecycle::Restorable
    restore_res::Dict{Blueprint,Int64}
    restore::Float64
    ProductBlueprint(name,
        lifecycle = Restorable();
        restore_res::Dict{Blueprint,Int64} = Dict{Blueprint,Int64}(),
        restore::Float64 = 0) = new(uuid4(), name, lifecycle, restore_res, restore)
end

The Restorable() constructor works. So does the ConsumableBlueprint() constructor.

Thanks in advance,
Stef

0 is of type Int, so the default value violates the type requirement. Just put a . after the number to indicate that it’s a Float :slight_smile: best of Luck!

Thanks! I changed the input type of the constructor to Real and now it works.