diff options
author | Jason Beetham <beefers331@gmail.com> | 2021-09-06 07:30:49 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-06 15:30:49 +0200 |
commit | 90bfd342504fd1a6a9e4c8f232bf7c35eab92f82 (patch) | |
tree | f0a1ff04f54e31373ed52ce09daec2967f4b8e7f | |
parent | cc5422ae5070a2cdd69dbd5b78663305623a0fbc (diff) | |
download | Nim-90bfd342504fd1a6a9e4c8f232bf7c35eab92f82.tar.gz |
'[]' can now be used for iterators (#18814)
-rw-r--r-- | compiler/semexprs.nim | 2 | ||||
-rw-r--r-- | tests/iter/tarrayiter.nim | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 3edeae324..c0a2a346a 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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) diff --git a/tests/iter/tarrayiter.nim b/tests/iter/tarrayiter.nim new file mode 100644 index 000000000..eb7ba591a --- /dev/null +++ b/tests/iter/tarrayiter.nim @@ -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 \ No newline at end of file |