From 9d9bf12e1ca283073d40e5ee817a6411c6f35734 Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Mon, 2 Nov 2020 17:58:14 +0800 Subject: [PATCH] Closure iterators are not supported by VM (#15818) (cherry picked from commit 5b4c17b5e7166220c7b5c149946579f245f54645) --- compiler/vmgen.nim | 2 ++ tests/vm/tclosureiterator.nim | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/vm/tclosureiterator.nim diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index aa8cd43477..21c19c2b19 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1982,6 +1982,8 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) = genRdVar(c, n, dest, flags) of skProc, skFunc, skConverter, skMacro, skTemplate, skMethod, skIterator: # 'skTemplate' is only allowed for 'getAst' support: + if s.kind == skIterator and s.typ.callConv == TCallingConvention.ccClosure: + globalError(c.config, n.info, "Closure iterators are not supported by VM!") if procIsCallback(c, s): discard elif importcCond(s): c.importcSym(n.info, s) genLit(c, n, dest) diff --git a/tests/vm/tclosureiterator.nim b/tests/vm/tclosureiterator.nim new file mode 100644 index 0000000000..c909392d55 --- /dev/null +++ b/tests/vm/tclosureiterator.nim @@ -0,0 +1,9 @@ +discard """ + errormsg: "Closure iterators are not supported by VM!" +""" + +iterator iter*(): int {.closure.} = + yield 3 + +static: + var x = iter