You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For collection types, I normally expect a constructor to copy it rather than returning it.
julia> x = []
Any[]
julia> y =Vector(x)
Any[]
julia> x === y
false
And for non-collection types with one field, it's not obvious that the result should even return a copy of the argument, rather than putting the argument into the field, as in a default constructor.
# Batteries
julia>mutable struct Foo
x
end
julia>@batteries Foo
Foo
julia> x =Foo([])
Foo(Any[])
julia> y =Foo(x)
Foo(Any[])
# Normal
julia>struct Bar
x
end
julia>Bar(Bar([]))
Bar(Bar(Any[]))
Because this constructor behaves in unusual ways, I don't think it should be enabled by default. I'd lean toward just removing the option.
The text was updated successfully, but these errors were encountered:
It is a good point, people might have different expectations of a selfconstructor. I agree, that selfconstructor=false may be the better default. But I am hesitant to do that breaking change.
StructHelpers.jl/src/StructHelpers.jl
Line 66 in 560b494
Because this constructor behaves in unusual ways, I don't think it should be enabled by default. I'd lean toward just removing the option.
The text was updated successfully, but these errors were encountered: