How to overload `ConstructionBase.setproperties` to change struct properties?

I want to change the value of certain properties in a struct. But Setfield is not working.


using Setfield

struct C{S,T, K}

c = C{Float64, Int, BitArray}(1.0,true)

@set! c.i = 2

ERROR: MethodError: no method matching C(::Int64, ::Bool)

How to overload ConstructionBase.setproperties to achieve the above?

The actual problem:

using Turing, Setfield

alg = NUTS(0.65)
@set! alg.max_depth = 4

ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Symbol
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:205
  Symbol(::Any...) at strings/basic.jl:229 

So overloading ConstructionBase.setproperties can do what I want. But I was not able get it right.


@using Setfield, ConstructionBase, Turing

alg = NUTS(0.65)

ConstructionBase.constructorof(::Type{NUTS{A, B, C}}) where {A, B, C} = (x…) → NUTS{A, B, C}(x…)

@set! alg.max_depth = 4