diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 7adfa0af23d9..2d3748236619 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -96,6 +96,7 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode, # current overload being considered var sym = syms[0].s let name = sym.name + let wantIterator = flags*{efInTypeof, efWantIterator, efWantIterable} != {} template addTypeBoundOpsFor(arg: PNode) = # add type bound ops for `name` based on the type of the arg `arg` if arg.typ != nil: @@ -108,7 +109,8 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode, var iter = default(TIdentIter) var s = initIdentIter(iter, c.graph.typeBoundOps[tid], name) while s != nil: - if not containsOrIncl(symMarker, s.id): + if (s.kind != skIterator or wantIterator) and + not containsOrIncl(symMarker, s.id): # least priority scope, less than explicit imports: syms.add((s, -2)) s = nextIdentIter(iter, c.graph.typeBoundOps[tid]) diff --git a/config/nim.cfg b/config/nim.cfg index 7c99581396df..e0b164ea68c3 100644 --- a/config/nim.cfg +++ b/config/nim.cfg @@ -18,6 +18,10 @@ cc = gcc hint[LineTooLong]=off @end +@if nimHasTypeBoundOps: + experimental:typeBoundOps +@end + #hint[XDeclaredButNotUsed]=off threads:on diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim index 660873d80503..0a3a4931095d 100644 --- a/lib/pure/collections/sequtils.nim +++ b/lib/pure/collections/sequtils.nim @@ -803,12 +803,6 @@ template anyIt*(s, pred: untyped): bool = break result -template toSeqIterable[T](s: iterable[T]): seq[T] = - var result: seq[T] = @[] - for it in s: - result.add(it) - result - template toSeq1(s: not iterator): untyped = # overload for typed but not iterator type OutType = typeof(items(s)) @@ -868,9 +862,7 @@ template toSeq*(iter: untyped): untyped = assert mySeq1 == @[1, 2, 3, 4, 5] assert mySeq2 == @[1'i8, 3, 5] - when compiles(toSeqIterable(iter)): - toSeqIterable(iter) - elif compiles(toSeq1(iter)): + when compiles(toSeq1(iter)): toSeq1(iter) elif compiles(toSeq2(iter)): toSeq2(iter) diff --git a/tests/stdlib/tsequtils.nim b/tests/stdlib/tsequtils.nim index 4a5c6d122596..1094ae2335eb 100644 --- a/tests/stdlib/tsequtils.nim +++ b/tests/stdlib/tsequtils.nim @@ -342,14 +342,9 @@ block: # toSeq test block: # tests https://github.com/nim-lang/Nim/issues/7187 counter = 0 - var s: seq[int] - for x in @[1, 2, 3].identity().filter(proc (x: int): bool = x < 3): - s.add(x) - let intendedCounter = counter - counter = 0 let ret = toSeq(@[1, 2, 3].identity().filter(proc (x: int): bool = x < 3)) doAssert ret == @[1, 2] - doAssert counter == intendedCounter + doAssert counter == 1 block: # foldl tests let numbers = @[5, 9, 11]