diff options
author | metagn <metagngn@gmail.com> | 2024-09-27 12:11:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-27 11:11:21 +0200 |
commit | dc3ffb6a71f36e3cfd1fc001d128a86b46c88e7a (patch) | |
tree | 29dd695e873bb786de7bdc2e4d3ea55a5722ec3d /tests | |
parent | 56a3dd57fb038cab2d00f6415435e701d2273573 (diff) | |
download | Nim-dc3ffb6a71f36e3cfd1fc001d128a86b46c88e7a.tar.gz |
consider calling convention and iterator in getType for procs (#24181)
fixes #19010 `getType` for proc types generated an `nkProcTy` for iterator types instead of `nkIteratorTy`, and didn't generate a calling convention pragma unless it was in the proc AST. Iterator types now generate `nkIteratorTy`, and a calling convention pragma is added if the calling convention isn't `closure` or was explicitly provided.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/macros/tmacrotypes.nim | 6 | ||||
-rw-r--r-- | tests/macros/tprocgettype.nim | 28 |
2 files changed, 31 insertions, 3 deletions
diff --git a/tests/macros/tmacrotypes.nim b/tests/macros/tmacrotypes.nim index 43819c81d..13b421303 100644 --- a/tests/macros/tmacrotypes.nim +++ b/tests/macros/tmacrotypes.nim @@ -1,9 +1,9 @@ discard """ - nimout: '''intProc; ntyProc; proc[int, int, float]; proc (a: int; b: float): int + nimout: '''intProc; ntyProc; proc[int, int, float]; proc (a: int; b: float): int {.nimcall.} void; ntyVoid; void; void int; ntyInt; int; int -proc (); ntyProc; proc[void]; proc () -voidProc; ntyProc; proc[void]; proc () +proc () {.nimcall.}; ntyProc; proc[void]; proc () {.nimcall.} +voidProc; ntyProc; proc[void]; proc () {.nimcall.} listing fields for ObjType a: string b: int diff --git a/tests/macros/tprocgettype.nim b/tests/macros/tprocgettype.nim new file mode 100644 index 000000000..0c1cc4270 --- /dev/null +++ b/tests/macros/tprocgettype.nim @@ -0,0 +1,28 @@ +discard """ + nimout: ''' +var x: proc () {.cdecl.} = foo +var x: iterator (): int {.closure.} = bar +''' +""" + +# issue #19010 + +import macros + +macro createVar(x: typed): untyped = + result = nnkVarSection.newTree: + newIdentDefs(ident"x", getTypeInst(x), copy(x)) + + echo repr result + +block: + proc foo() {.cdecl.} = discard + + createVar(foo) + x() + +block: + iterator bar(): int {.closure.} = discard + + createVar(bar) + for a in x(): discard |