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

Nim doesn't catch wrong var {.global.} initialization #3505

Closed
Wh1teDuke opened this issue Nov 1, 2015 · 4 comments · Fixed by #20812
Closed

Nim doesn't catch wrong var {.global.} initialization #3505

Wh1teDuke opened this issue Nov 1, 2015 · 4 comments · Fixed by #20812

Comments

@Wh1teDuke
Copy link
Contributor

Wh1teDuke commented Nov 1, 2015

Test

proc foo =
  let a = 0
  var b {.global.} = a # Nim should complain about this
foo()

Result:

>nim c test
[...]\nimcache\compiler_test.c:100:12: error: 'a' undeclared (first use in this f
unction)
  b_97006 = a;
            ^
Error: execution of an external program failed: [...]

>nim -v
Nim Compiler Version 0.12.0 (2015-10-28) [Windows: i386]
Copyright (c) 2006-2015 by Andreas Rumpf

git hash: 22a702868bfd242ff76bf86ea00a278f979a112e
active boot switches: -d:release
@stale
Copy link

stale bot commented Aug 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Aug 4, 2020
@ghost ghost added the {.global.} label Aug 4, 2020
@stale stale bot removed the stale Staled PR/issues; remove the label after fixing them label Aug 4, 2020
@bung87
Copy link
Collaborator

bung87 commented Oct 26, 2022

this works in current devel 3b973f3, and similar issues are closed, guess it's just reopened by adding a label.

@ringabout
Copy link
Member

this works in current devel 3b973f3, and similar issues are closed, guess it's just reopened by adding a label.

It doesn't work if the proc gets called

proc foo =
  let a = 0
  var b {.global.} = a # Nim should complain about this

foo()
C:\Users\blue\Documents\GitHub\Nim\test3.nim(3, 7) Hint: 'b' is declared but not used [XDeclaredButNotUsed]
CC: ../../../.choosenim/toolchains/nim-#devel/lib/system/exceptions.nim
CC: ../../../.choosenim/toolchains/nim-#devel/lib/system.nim
CC: test3.nim
C:\Users\blue\nimcache\test3_d\@mtest3.nim.c: In function 'NimMainModule':
C:\Users\blue\nimcache\test3_d\@mtest3.nim.c:229:23: error: 'a' undeclared (first use in this function)
  229 |         b__test51_3 = a;
      |                       ^

@bung87
Copy link
Collaborator

bung87 commented Oct 26, 2022

hmm, seems like we need transform the lvalue to global too.

bung87 added a commit to bung87/Nim that referenced this issue Nov 11, 2022
bung87 added a commit to bung87/Nim that referenced this issue Nov 11, 2022
Araq added a commit that referenced this issue Nov 12, 2022
…20812)

* fix #3505 wrong var {.global.} initialization, asign variable to it

* fix #5132 as well

* follow suggestions

* handle all call kinds

* Update tests/global/t3505.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* follow suggestion

* Update compiler/semstmts.nim

Co-authored-by: Andreas Rumpf <[email protected]>
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
… to it (nim-lang#20812)

* fix nim-lang#3505 wrong var {.global.} initialization, asign variable to it

* fix nim-lang#5132 as well

* follow suggestions

* handle all call kinds

* Update tests/global/t3505.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* follow suggestion

* Update compiler/semstmts.nim

Co-authored-by: Andreas Rumpf <[email protected]>
narimiran pushed a commit that referenced this issue Apr 25, 2023
…20812)

* fix #3505 wrong var {.global.} initialization, asign variable to it

* fix #5132 as well

* follow suggestions

* handle all call kinds

* Update tests/global/t3505.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* follow suggestion

* Update compiler/semstmts.nim

Co-authored-by: Andreas Rumpf <[email protected]>
(cherry picked from commit 1410243)
narimiran pushed a commit that referenced this issue Apr 25, 2023
…20812)

* fix #3505 wrong var {.global.} initialization, asign variable to it

* fix #5132 as well

* follow suggestions

* handle all call kinds

* Update tests/global/t3505.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* follow suggestion

* Update compiler/semstmts.nim

Co-authored-by: Andreas Rumpf <[email protected]>
(cherry picked from commit 1410243)
narimiran pushed a commit that referenced this issue Apr 25, 2023
…20812)

* fix #3505 wrong var {.global.} initialization, asign variable to it

* fix #5132 as well

* follow suggestions

* handle all call kinds

* Update tests/global/t3505.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* follow suggestion

* Update compiler/semstmts.nim

Co-authored-by: Andreas Rumpf <[email protected]>
(cherry picked from commit 1410243)
narimiran pushed a commit that referenced this issue Apr 25, 2023
…20812)

* fix #3505 wrong var {.global.} initialization, asign variable to it

* fix #5132 as well

* follow suggestions

* handle all call kinds

* Update tests/global/t3505.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* follow suggestion

* Update compiler/semstmts.nim

Co-authored-by: Andreas Rumpf <[email protected]>
(cherry picked from commit 1410243)
narimiran pushed a commit that referenced this issue Apr 26, 2023
…20812)

* fix #3505 wrong var {.global.} initialization, asign variable to it

* fix #5132 as well

* follow suggestions

* handle all call kinds

* Update tests/global/t3505.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* follow suggestion

* Update compiler/semstmts.nim

Co-authored-by: Andreas Rumpf <[email protected]>
(cherry picked from commit 1410243)
bung87 added a commit to bung87/Nim that referenced this issue Jul 29, 2023
… to it (nim-lang#20812)

* fix nim-lang#3505 wrong var {.global.} initialization, asign variable to it

* fix nim-lang#5132 as well

* follow suggestions

* handle all call kinds

* Update tests/global/t3505.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* Update compiler/semstmts.nim

* follow suggestion

* Update compiler/semstmts.nim

Co-authored-by: Andreas Rumpf <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants