diff options
Diffstat (limited to 'tests/global')
-rw-r--r-- | tests/global/a_module.nim | 6 | ||||
-rw-r--r-- | tests/global/t15005.nim | 18 | ||||
-rw-r--r-- | tests/global/t21896.nim | 9 | ||||
-rw-r--r-- | tests/global/tglobal2.nim | 9 |
4 files changed, 42 insertions, 0 deletions
diff --git a/tests/global/a_module.nim b/tests/global/a_module.nim new file mode 100644 index 000000000..1d3f4848c --- /dev/null +++ b/tests/global/a_module.nim @@ -0,0 +1,6 @@ +# a.nim +{.push stackTrace: off.} +proc foo*(): int = + var a {.global.} = 0 + result = a +{.pop.} \ No newline at end of file diff --git a/tests/global/t15005.nim b/tests/global/t15005.nim new file mode 100644 index 000000000..6395b1dde --- /dev/null +++ b/tests/global/t15005.nim @@ -0,0 +1,18 @@ +type + T = ref object + data: string + +template foo(): T = + var a15005 {.global.}: T + once: + a15005 = T(data: "hi") + + a15005 + +proc test() = + var b15005 = foo() + + doAssert b15005.data == "hi" + +test() +test() diff --git a/tests/global/t21896.nim b/tests/global/t21896.nim new file mode 100644 index 000000000..c7765c4dd --- /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) diff --git a/tests/global/tglobal2.nim b/tests/global/tglobal2.nim new file mode 100644 index 000000000..73a575bbd --- /dev/null +++ b/tests/global/tglobal2.nim @@ -0,0 +1,9 @@ +# b.nim +import a_module +doAssert foo() == 0 + +proc hello(x: type) = + var s {.global.} = default(x) + doAssert s == 0 + +hello(int) |