I ran into this as well. I assumed it would be the same as overriding getindex and setindex!, and was surprised by the different behavior.
On Saturday, August 15, 2015 at 11:05:31 PM UTC-4, Dominique Orban wrote: > > Excellent, thanks. I searched through issues but didn't hit that one. > > On Saturday, August 15, 2015 at 10:39:27 PM UTC-4, Tony Kelman wrote: >> >> Not yet. Maybe for 0.5? >> >> https://github.com/JuliaLang/julia/issues/1974 >> >> >> On Saturday, August 15, 2015 at 7:35:20 PM UTC-7, Dominique Orban wrote: >>> >>> I'm wondering if implementing getfield() / setfield!() for a composite >>> type could be a good design for getters and setters. Say I have a type >>> >>> type Thing >>> a :: Int >>> b :: int >>> end >>> >>> where I'm requiring the `a` field to be even. It'd be great to be able >>> to type >>> >>> thing = Thing() >>> thing.a = 3 >>> >>> and receive an error. >>> >>> In 0.3.10 and 0.4, I can't implement setfield!(): >>> ERROR: cannot define function setfield!; it already has a value. >>> >>> Is there a way to do this? >>> >>