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

{.global.} variable definition order does not match the manual #24665

Open
carrexxii opened this issue Feb 4, 2025 · 0 comments
Open

{.global.} variable definition order does not match the manual #24665

carrexxii opened this issue Feb 4, 2025 · 0 comments

Comments

@carrexxii
Copy link

Description

According to the manual: "The order of initialization of the created global variables within a module is not defined, but all of them will be initialized after any top-level variables in their originating module and before any variable in a module that imports it."

proc a(): int = echo "a"; 1
proc b(): int = echo "b"; 2
proc c(): int = echo "c"; 3

var g = a()

proc run() =
  var x {.global.} = b()
  var y {.global.} = c()
  
run()

The {.global.}s are being initialized before the top-level variable which prevents initializing a value they depend on.

Nim Version

Nim Compiler Version 2.2.0 [Linux: amd64]
Compiled at 2024-10-02
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 78983f1
active boot switches: -d:release

Current Output

b
c
a

Expected Output

a
b
c

or

a
c
b

Known Workarounds

No response

Additional Information

No response

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