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

Support const syntax for mutable structs in lazy field #34

Open
Tortar opened this issue Dec 30, 2023 · 0 comments · May be fixed by #35
Open

Support const syntax for mutable structs in lazy field #34

Tortar opened this issue Dec 30, 2023 · 0 comments · May be fixed by #35

Comments

@Tortar
Copy link

Tortar commented Dec 30, 2023

It doesn't seem to work currently:

julia> @lazy mutable struct A
           const x::Int
           @lazy const y::Int
ERROR: ParseError:
# Error @ REPL[12]:3:11
    const x::Int
    @lazy const y::Int
#         └──────────┘ ── expected assignment after `const`
Stacktrace:
 [1] top-level scope
   @ none:1

actually given this is a parse error, it is probably necessary to go instead with

julia> @lazy mutable struct A
           const x::Int
           const @lazy y::Int
       end
ERROR: LoadError: expected a @lazy field inside the struct
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] lazy_struct(expr::Expr, mod::Module)
   @ LazilyInitializedFields ~/.julia/packages/LazilyInitializedFields/EAhdM/src/LazilyInitializedFields.jl:307
 [3] var"@lazy"(__source__::LineNumberNode, __module__::Module, expr::Any)
   @ LazilyInitializedFields ~/.julia/packages/LazilyInitializedFields/EAhdM/src/LazilyInitializedFields.jl:264
in expression starting at REPL[13]:1

This is useful when you don't really want to initialize always that field in all cases, but only for some instances, but if it is initiliazed to an actual value you want that it can't be changed (as in my case)

@Tortar Tortar linked a pull request Dec 30, 2023 that will close this issue
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