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

@kwdef doesn't allow @atomic fields with default values #56932

Open
JamesWrigley opened this issue Jan 1, 2025 · 0 comments
Open

@kwdef doesn't allow @atomic fields with default values #56932

JamesWrigley opened this issue Jan 1, 2025 · 0 comments

Comments

@JamesWrigley
Copy link
Contributor

MWE:

julia> @kwdef mutable struct Foo
           @atomic x::Int
       end
Foo

julia> @kwdef mutable struct Bar
           @atomic x::Int = 1
       end
ERROR: LoadError: @atomic modify expression missing field access
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] make_atomic(order::Any, a1::Any, op::Any, a2::Any)
   @ Base ./expr.jl:1240
 [3] make_atomic(order::Any, ex::Any)
   @ Base ./expr.jl:1232
 [4] var"@atomic"(__source__::LineNumberNode, __module__::Module, ex::Any)
   @ Base ./expr.jl:1190
 [5] #macroexpand#74
   @ ./expr.jl:125 [inlined]
 [6] macroexpand(m::Module, x::Any)
   @ Base ./expr.jl:123
 [7] var"@kwdef"(__source__::LineNumberNode, __module__::Module, expr::Any)
   @ Base ./util.jl:564
in expression starting at REPL[3]:1

The exception is coming from here where the struct expression is expanded:

expr = macroexpand(__module__, expr) # to expand @static

To fix this I think the code would need to go through the expr before the macroexpand to remove and record field atomicity, and then insert @atomic for those fields in the generated constructor. Related issue: #45020

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

1 participant