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.} and const interact weirdly #11285

Open
davidgarland opened this issue May 20, 2019 · 2 comments
Open

{.global.} and const interact weirdly #11285

davidgarland opened this issue May 20, 2019 · 2 comments
Labels

Comments

@davidgarland
Copy link

The current behavior for const and {.global.} is somewhat confusing; I'm not sure if this is intended behavior or not.

Example

proc unique: int =
  var id {.global.} = 0
  result = id
  id += 1

const x = unique()
const y = unique()

let z = unique()
let w = unique()

echo x
echo y
echo z
echo w

Current Output

0
0
0
1

Expected Output

Either

0
1
0
1

or

0
1
2
3

depending upon what is deemed "correct."

@davidgarland
Copy link
Author

Upon trying using a literal global variable that seems to fail, so perhaps the intended behavior should be that the compiler just errors upon {.global.} being used at compile time instead?

@krux02
Copy link
Contributor

krux02 commented May 20, 2019

@davidgarland I agree, the compiler should signal an error when {.global.} is used at compile time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants