From 266cc69f1973773228534f074febd153c472b949 Mon Sep 17 00:00:00 2001 From: Bung Date: Wed, 24 May 2023 21:30:14 +0800 Subject: [PATCH] fix #21896 asign parameter to global variable generates invalid code (#21900) --- compiler/semstmts.nim | 2 +- tests/global/t21896.nim | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/global/t21896.nim diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 579af973ef..6e2fb92528 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -563,7 +563,7 @@ proc semVarMacroPragma(c: PContext, a: PNode, n: PNode): PNode = return result template isLocalSym(sym: PSym): bool = - sym.kind in {skVar, skLet} and not + sym.kind in {skVar, skLet, skParam} and not ({sfGlobal, sfPure} * sym.flags != {} or sfCompileTime in sym.flags) or sym.kind in {skProc, skFunc, skIterator} and diff --git a/tests/global/t21896.nim b/tests/global/t21896.nim new file mode 100644 index 0000000000..c7765c4dd1 --- /dev/null +++ b/tests/global/t21896.nim @@ -0,0 +1,9 @@ +discard """ + errormsg: "cannot assign local to global variable" + line: 7 +""" + +proc example(a:int) = + let b {.global.} = a + +example(1)