1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- discard """
- matrix: "--mm:refc; --mm:orc"
- targets: "c cpp js"
- """
- # xxx merge with tests/metatype/ttypetraits.nim
- import std/typetraits
- import std/assertions
- macro testClosure(fn: typed, flag: static bool) =
- if flag:
- doAssert hasClosure(fn)
- else:
- doAssert not hasClosure(fn)
- block:
- proc h1() =
- echo 1
- testClosure(h1, false)
- proc h2() {.nimcall.} =
- echo 2
- testClosure(h2, false)
- block:
- proc fn(): auto =
- proc hello() {.nimcall.} =
- echo 3
- hello
- let name = fn()
- testClosure(name, false)
- block:
- proc fn(): auto =
- proc hello() =
- echo 3
- hello
- let name = fn()
- testClosure(name, false)
- block:
- proc fn(): auto =
- var x = 0
- proc hello() =
- echo 3
- inc x
- hello
- let name = fn()
- testClosure(name, true)
- block:
- proc fn(): auto =
- var x = 0
- proc hello() {.closure.} =
- echo 3
- inc x
- hello
- let name = fn()
- testClosure(name, true)
- block:
- proc fn(): auto =
- var x = 0
- proc hello() {.closure.} =
- echo 3
- inc x
- hello
- let name = fn()
- testClosure(name, true)
- let name2 = name
- testClosure(name2, true)
- block:
- iterator hello(): int =
- yield 1
- testClosure(hello, false)
- when not defined(js):
- block:
- iterator hello(): int {.closure.}=
- yield 1
- testClosure(hello, true)
|