From be3583e3e4717b56d85a016794a20f30491ac5a7 Mon Sep 17 00:00:00 2001 From: flywind Date: Mon, 2 Nov 2020 21:48:03 +0800 Subject: [PATCH] follow #15818 and close #7109 --- compiler/jsgen.nim | 7 +++++-- tests/js/t7109.nim | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/js/t7109.nim diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 10c0722534a48..b76db68bb3c2d 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -2549,9 +2549,12 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) = of nkAsmStmt: genAsmOrEmitStmt(p, n) of nkTryStmt, nkHiddenTryStmt: genTry(p, n, r) of nkRaiseStmt: genRaiseStmt(p, n) - of nkTypeSection, nkCommentStmt, nkIteratorDef, nkIncludeStmt, + of nkTypeSection, nkCommentStmt, nkIncludeStmt, nkImportStmt, nkImportExceptStmt, nkExportStmt, nkExportExceptStmt, nkFromStmt, nkTemplateDef, nkMacroDef, nkStaticStmt: discard + of nkIteratorDef: + if n[0].sym.typ.callConv == TCallingConvention.ccClosure: + globalError(p.config, n.info, "Closure iterators are not supported by JS backend!") of nkPragma: genPragma(p, n) of nkProcDef, nkFuncDef, nkMethodDef, nkConverterDef: var s = n[namePos].sym @@ -2559,7 +2562,7 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) = genSym(p, n[namePos], r) r.res = nil of nkGotoState, nkState: - internalError(p.config, n.info, "first class iterators not implemented") + globalError(p.config, n.info, "first class iterators not implemented") of nkPragmaBlock: gen(p, n.lastSon, r) of nkComesFrom: discard "XXX to implement for better stack traces" diff --git a/tests/js/t7109.nim b/tests/js/t7109.nim new file mode 100644 index 0000000000000..0d071dbbf33e7 --- /dev/null +++ b/tests/js/t7109.nim @@ -0,0 +1,8 @@ +discard """ + errormsg: "Closure iterators are not supported by JS backend!" +""" + +iterator iter*(): int {.closure.} = + yield 3 + +var x = iter