summary refs log tree commit diff stats
path: root/tests/array/troofregression.nim
diff options
context:
space:
mode:
authorDaniil Yarancev <21169548+Yardanico@users.noreply.github.com>2018-01-07 21:02:00 +0300
committerGitHub <noreply@github.com>2018-01-07 21:02:00 +0300
commitfb44c522e6173528efa8035ecc459c84887d0167 (patch)
treea2f5e98606be265981a5f72748896967033e23d7 /tests/array/troofregression.nim
parentccf99fa5ce4fe992fb80dc89271faa51456c3fa5 (diff)
parente23ea64c41e101d4e1d933f0b015f51cc6c2f7de (diff)
downloadNim-fb44c522e6173528efa8035ecc459c84887d0167.tar.gz
Merge pull request #1 from nim-lang/devel
upstream
Diffstat (limited to 'tests/array/troofregression.nim')
-rw-r--r--tests/array/troofregression.nim46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/array/troofregression.nim b/tests/array/troofregression.nim
new file mode 100644
index 000000000..0b96123a4
--- /dev/null
+++ b/tests/array/troofregression.nim
@@ -0,0 +1,46 @@
+###############################
+#### part from Arraymancer
+
+type
+  MetadataArray* = object
+    data*: array[8, int]
+    len*: int
+
+# Commenting the converter removes the error "lib/system.nim(3536, 3) Error: for a 'var' type a variable needs to be passed"
+converter toMetadataArray*(se: varargs[int]): MetadataArray {.inline.} =
+  result.len = se.len
+  for i in 0..<se.len:
+    result.data[i] = se[i]
+
+
+when NimVersion >= "0.17.3":
+  type Index = int or BackwardsIndex
+  template `^^`(s, i: untyped): untyped =
+    when i is BackwardsIndex:
+      s.len - int(i)
+    else: i
+else:
+  type Index = int
+  template `^^`(s, i: untyped): untyped =
+    i
+
+## With Nim devel from the start of the week (~Oct30) I managed to trigger "lib/system.nim(3536, 4) Error: expression has no address"
+## but I can't anymore after updating Nim (Nov5)
+## Now commenting this plain compiles and removes the error "lib/system.nim(3536, 3) Error: for a 'var' type a variable needs to be passed"
+proc `[]`*(a: var MetadataArray, idx: Index): var int {.inline.} =
+  a.data[a ^^ idx]
+
+
+##############################
+### Completely unrelated lib that triggers the issue
+
+type
+  MySeq[T] = ref object
+    data: seq[T]
+
+proc test[T](sx: MySeq[T]) =
+  # Removing the backward index removes the error "lib/system.nim(3536, 3) Error: for a 'var' type a variable needs to be passed"
+  echo sx.data[^1] # error here
+
+let s = MySeq[int](data: @[1, 2, 3])
+s.test()
05 - example program for line-oriented input' href='/akkartik/mu/commit/buffered-stdin.mu?h=main&id=3a0be565881da3da34b2b5cd1bb2b7c6a88a4910'>3a0be565 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28