summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJason Beetham <beefers331@gmail.com>2021-09-06 07:30:49 -0600
committerGitHub <noreply@github.com>2021-09-06 15:30:49 +0200
commit90bfd342504fd1a6a9e4c8f232bf7c35eab92f82 (patch)
treef0a1ff04f54e31373ed52ce09daec2967f4b8e7f
parentcc5422ae5070a2cdd69dbd5b78663305623a0fbc (diff)
downloadNim-90bfd342504fd1a6a9e4c8f232bf7c35eab92f82.tar.gz
'[]' can now be used for iterators (#18814)
-rw-r--r--compiler/semexprs.nim2
-rw-r--r--tests/iter/tarrayiter.nim14
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