Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with outer-only constructors #44

Closed
IlyaOrson opened this issue Jan 18, 2022 · 1 comment
Closed

Does not work with outer-only constructors #44

IlyaOrson opened this issue Jan 18, 2022 · 1 comment

Comments

@IlyaOrson
Copy link

IlyaOrson commented Jan 18, 2022

Just wondering if this is a bug or a feature. Using the julia docs example:

julia> struct SummedArray{T<:Number,S<:Number}
           data::Vector{T}
           sum::S
           function SummedArray(a::Vector{T}) where T
               S = widen(T)
               new{T,S}(a, sum(S, a))
           end
       end

julia> sa = SummedArray([1,2,3])
SummedArray{Int64, Int128}([1, 2, 3], 6)

julia> @set sa.sum = 5
ERROR: MethodError: no method matching SummedArray(::Vector{Int64}, ::Int64)
Closest candidates are:
  SummedArray(::Vector{T}) where T at REPL[14]:4
Stacktrace:
 [1] setproperties_object(obj::SummedArray{Int64, Int128}, patch::NamedTuple{(:sum,), Tuple{Int64}})
   @ ConstructionBase C:\Users\ilyao\.julia\packages\ConstructionBase\N3vfl\src\ConstructionBase.jl:149
 [2] setproperties(obj::SummedArray{Int64, Int128}, patch::NamedTuple{(:sum,), Tuple{Int64}})
   @ ConstructionBase C:\Users\ilyao\.julia\packages\ConstructionBase\N3vfl\src\ConstructionBase.jl:63
 [3] set(obj::SummedArray{Int64, Int128}, l::Accessors.PropertyLens{:sum}, val::Int64)
   @ Accessors C:\Users\ilyao\.julia\packages\Accessors\KLYEx\src\optics.jl:376
 [4] top-level scope
   @ REPL[16]:1
@jw3126
Copy link
Member

jw3126 commented Jan 18, 2022

You can overload ConstructionBase.setproperties for types with inner constructors https://github.com/JuliaObjects/ConstructionBase.jl

@aplavin aplavin closed this as completed Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants