Setfield.jl icon indicating copy to clipboard operation
Setfield.jl copied to clipboard

Is this expected behavior?

Open krishvishal opened this issue 3 years ago • 2 comments

Env:

julia = 1.6.1 Setfield = 0.7.1

MWE:


using Setfield
struct C{S,T}
    i::T
end

c = C{Float64,Int}(1)
d = C{Float64, Int}(2)

Case 1: @set c.i = 2 #MethodError: no method matching C(::Int64)

Case 2: @set c.i, d.i = d.i, c.i #Doesn't fail but doesn't swap attributes either. 

Case 3: @set! c.i, d.i = d.i, c.i  #ERROR: setfield! immutable struct of type C cannot be changed

I feel Case 2 is a silent failure. Can someone please clarify this for me.

krishvishal avatar Jul 07 '22 20:07 krishvishal

Interesting. @set does not support such multi-assignments. I agree it would be nice if we could throw a sane error in this case.

jw3126 avatar Jul 07 '22 21:07 jw3126

I've updated case 3. I didn't pay attention while pasting.

krishvishal avatar Jul 07 '22 21:07 krishvishal