mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-11 22:08:54 +00:00
'[]' can now be used for iterators (#18814)
This commit is contained in:
@@ -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)
|
||||
|
||||
14
tests/iter/tarrayiter.nim
Normal file
14
tests/iter/tarrayiter.nim
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user