fix #3505 wrong var {.global.} initialization, asign variable to it (#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 <rumpf_a@web.de>
This commit is contained in:
Bung 2022-11-13 05:57:07 +08:00 • committed by GitHub
commit 1410243d3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 1 deletions

33
tests/global/t3505.nim Normal file
View file

@ -0,0 +1,33 @@
discard """
cmd: "nim check $options --hints:off $file"
action: "reject"
nimout: '''
t3505.nim(22, 22) Error: cannot assign local to global variable
t3505.nim(31, 28) Error: cannot assign local to global variable
'''
"""
proc foo =
let a = 0
var b {.global.} = a
foo()
# issue #5132
proc initX(it: float): int = 8
proc initX2(it: int): int = it
proc main() =
var f: float
var x {.global.} = initX2(initX(f))
main()