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

Base.@kwdef structs constructor ignores @atomic fields #45020

Closed
dpinol opened this issue Apr 18, 2022 · 0 comments · Fixed by #46276
Closed

Base.@kwdef structs constructor ignores @atomic fields #45020

dpinol opened this issue Apr 18, 2022 · 0 comments · Fixed by #46276

Comments

@dpinol
Copy link

dpinol commented Apr 18, 2022

When the struct has non-atomic fields, a named args constructor is created but without the atomic field argument.


julia> Base.@kwdef mutable struct KWD
       @atomic atom::Int
       kk::String
       end
KWD

julia> methods(KWD)
# 3 methods for type constructor:
[1] KWD(; kk) in Main at util.jl:478
[2] KWD(atom::Int64, kk::String) in Main at REPL[5]:2
[3] KWD(atom, kk) in Main at REPL[5]:2

When the struct has only atomic fields, no named args constructor is created

julia> Base.@kwdef mutable struct KWD2
       @atomic atom::Int
       end

julia> methods(KWD2)
# 2 methods for type constructor:
[1] KWD2(atom::Int64) in Main at REPL[1]:2
[2] KWD2(atom) in Main at REPL[1]:2

thanks

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

Successfully merging a pull request may close this issue.

1 participant