Skip to content

Commit

Permalink
'[]' can now be used for iterators (nim-lang#18814)
Browse files Browse the repository at this point in the history
  • Loading branch information
beef331 authored and PMunch committed Mar 28, 2022
1 parent 5e6eaf8 commit 17aae0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ proc semArrayAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
result = semSubscript(c, n, flags)
if result == nil:
# overloaded [] operator:
result = semExpr(c, buildOverloadedSubscripts(n, getIdent(c.cache, "[]")))
result = semExpr(c, buildOverloadedSubscripts(n, getIdent(c.cache, "[]")), flags)

proc propertyWriteAccess(c: PContext, n, nOrig, a: PNode): PNode =
var id = considerQuotedIdent(c, a[1], a)
Expand Down
14 changes: 14 additions & 0 deletions tests/iter/tarrayiter.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
block:
iterator `[]`(a: int, r: int): int =
for q in 0 .. r:
yield a

for val in 10[2]: discard

type Custom = distinct string

iterator `[]`(a: Custom, r: int): char =
for q in 0 .. r:
yield a.string[q]

for val in Custom("test")[2]: discard

0 comments on commit 17aae0f

Please sign in to comment.