← Back to context

Comment by ptx

3 years ago

Maybe I misunderstood then. I was saying that it seems to behave basically like Java. Is that a bug?

V has global consts, they are immutable, but can be initialized with complex expressions, for example

`const x = foo()`

There's a bug that allows to trick the compiler and modify the const via another variable, it's a one line fix, and will be fixed today.

Global mutable variables are only allowed with `-enable-globals` and are supposed to be used only in low level code, like drivers and kernels.

  • If I understand the example code correctly, it's modifying a heap-allocated struct that's pointed to by a global const. So the global const contains an address which is not modified, but the thing at that address is modified. Right?

    What does the intended behaviour (after the fix) look like? Are mutable fields in structs disallowed if the struct is pointed to by a const?