Why does this constructor not work with 1 Int parameter?

Problem can be solved by removing restrictions in Mechanical (there is no need in them anyway)

Mechanical(
           health::Real = 1;
           damage_thresholds = [],
           repair_thresholds = []
) = Mechanical(Percentage(health), damage_thresholds, repair_thresholds)

julia> Mechanical(1)
Mechanical(Percentage(1.0), Tuple{Percentage,Float64}[], Tuple{Percentage,Float64}[])

Rule of thumb: remove arguments restrictions in functions and introduce them only it is really necessary.

3 Likes