Getting warning Cannot declare constant; it already has a value

I have a mutable struct that is giving me a warning Cannot declare constant; it already has a value. I do not declare const for any values in my struct constructor.

I’m still quite new to Julia so I’m not too understanding yet about the way it holds objects in memory and whatnot.

struct definitions are constants, so redefining a struct with the same name leads to the warning.

This does not have anything to do with mutability or how julia objects are laid out in memory.

If you’re not yet sure how many fields your struct should have, consider experimenting with a Named Tuple first, and transitioning to a struct later on (using accessor functions to get fields etc.) once performance becomes a concern.

1 Like