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

Is this expected behavior? #171

Open
krishvishal opened this issue Jul 7, 2022 · 2 comments
Open

Is this expected behavior? #171

krishvishal opened this issue Jul 7, 2022 · 2 comments

Comments

@krishvishal
Copy link

krishvishal commented Jul 7, 2022

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.

@jw3126
Copy link
Owner

jw3126 commented Jul 7, 2022

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

@krishvishal
Copy link
Author

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

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

2 participants