From c80261bc00c2be59216f945e7915699f6adab690 Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Mon, 4 Jan 2021 03:24:52 -0600 Subject: [PATCH] fix #12311 (#16578) --- lib/system.nim | 11 +++++++---- tests/system/tsystem_misc.nim | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/system.nim b/lib/system.nim index 618fd5dd76..e220ba7a39 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2412,10 +2412,13 @@ when notJSnotNims: {.error: "Only closure function and iterator are allowed!".} proc finished*[T: proc](x: T): bool {.noSideEffect, inline.} = - ## can be used to determine if a first class iterator has finished. - {.emit: """ - `result` = ((NI*) `x`.ClE_0)[1] < 0; - """.} + ## It can be used to determine if a first class iterator has finished. + when T is "iterator": + {.emit: """ + `result` = ((NI*) `x`.ClE_0)[1] < 0; + """.} + else: + {.error: "Only closure iterator is allowed!".} when defined(js): include "system/jssys" diff --git a/tests/system/tsystem_misc.nim b/tests/system/tsystem_misc.nim index 508715905e..cb879d3b3d 100644 --- a/tests/system/tsystem_misc.nim +++ b/tests/system/tsystem_misc.nim @@ -210,3 +210,10 @@ block: # Ordinal # doAssert enum is Ordinal # fails # doAssert Ordinal is SomeOrdinal # doAssert SomeOrdinal is Ordinal + +block: + proc p() = discard + + doAssert not compiles(echo p.rawProc.repr) + doAssert not compiles(echo p.rawEnv.repr) + doAssert not compiles(echo p.finished)