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/t3505.nim | 41 | ||||
-rw-r--r-- | tests/global/tglobal2.nim | 9 |
5 files changed, 83 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/t3505.nim b/tests/global/t3505.nim new file mode 100644 index 000000000..437a02ae6 --- /dev/null +++ b/tests/global/t3505.nim @@ -0,0 +1,41 @@ +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 +t3505.nim(39, 29) 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() + +# issue #20866 +proc foo2() = + iterator bar() {.closure.} = + discard + var g {.global.} = rawProc(bar) + +foo2() \ No newline at end of file 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) |