Skip to content

Commit

Permalink
fix iterators, revert sequtils changes, temp enable globally
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Oct 16, 2024
1 parent 3c60d4a commit 77790e4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
4 changes: 3 additions & 1 deletion compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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])
Expand Down
4 changes: 4 additions & 0 deletions config/nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ cc = gcc
hint[LineTooLong]=off
@end

@if nimHasTypeBoundOps:
experimental:typeBoundOps
@end

#hint[XDeclaredButNotUsed]=off

threads:on
Expand Down
10 changes: 1 addition & 9 deletions lib/pure/collections/sequtils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions tests/stdlib/tsequtils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 77790e4

Please sign in to comment.