# I don't see any caveats in \`Setfield.jl / Accessors.jl\`, but I'm getting a method

**URL:** <https://discourse.julialang.org/t/i-dont-see-any-caveats-in-setfield-jl-accessors-jl-but-im-getting-a-method/54657>\
**Category:** General Usage\
**Tags:** accessors\
**Created:** [February 4, 2021, 10:06pm UTC](https://discourse.julialang.org/t/i-dont-see-any-caveats-in-setfield-jl-accessors-jl-but-im-getting-a-method/54657 "2021-02-04T22:06:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [February 4, 2021, 10:06pm UTC](https://discourse.julialang.org/t/i-dont-see-any-caveats-in-setfield-jl-accessors-jl-but-im-getting-a-method/54657/1 "2021-02-04T22:06:06Z")

</div>

I don’t see any caveats in `Setfield.jl / Accessors.jl`, but I’m getting a method error (`ERROR: LoadError: MethodError: no method matching`) for the constructor that I’m trying to mutate. Are limitations outlined anywhere?

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1612476326089900?thread_ts=1612476326.089900&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [February 4, 2021, 10:17pm UTC](https://discourse.julialang.org/t/i-dont-see-any-caveats-in-setfield-jl-accessors-jl-but-im-getting-a-method/54657/2 "2021-02-04T22:17:49Z")

</div>

please post the line that errors

---

<div class="post-metadata">

**Author:** ![charleskawczynski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charleskawczynski/32/13783_2.png) [@charleskawczynski](https://discourse.julialang.org/u/charleskawczynski)\
**Post date:** [February 4, 2021, 11:14pm UTC](https://discourse.julialang.org/t/i-dont-see-any-caveats-in-setfield-jl-accessors-jl-but-im-getting-a-method/54657/3 "2021-02-04T23:14:34Z")

</div>

It took a bit to track down what the problem was. It seems that certain constructors must exist:

```julia
struct Foo{FT,A,B}
a::A
b::B
end

Foo{FT}(a::A,b::B) where {FT,A,B} = Foo{FT,A,B}(a,b)

f = Foo{Float64}(1, (;x=1,y=2))

using Accessors

# Fails:
@set f.b = (;x=2,y=1)

# Need this definition:
Foo(a,b) = Foo{typeof(a),typeof(a),typeof(b)}(a,b)

# Now works:
@set f.b = (;x=2,y=1)

```

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [February 5, 2021, 7:59am UTC](https://discourse.julialang.org/t/i-dont-see-any-caveats-in-setfield-jl-accessors-jl-but-im-getting-a-method/54657/4 "2021-02-05T07:59:25Z")

</div>

You can overload `constructorof` or `setproperties`. See [here](https://juliaobjects.github.io/ConstructionBase.jl/stable/#ConstructionBase.constructorof).

A PR that adds a HowTo to the [Accessors.jl](https://juliaobjects.github.io/Accessors.jl/stable/) docs would be amazing!
