summary refs log tree commit diff stats
path: root/tests/array/troofregression.nim
blob: 0b96123a4aa5514928c82f553455b4994ed31e82 (plain) (blame)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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()
1040 is 1030 mem/0: storing 3 in location 1041 run/0: instruction string-equal/3 run/0: product 0 is 1034 mem/0: storing 1034 in location 1042 run/0: instruction string-equal/4 mem/0: location 1042 is 1034 mem/0: storing 3 in location 1043 run/0: instruction string-equal/6 string-equal/0: comparing lengths run/0: instruction string-equal/7 run/0: ingredient 0 is a-len mem/0: location 1041 is 3 run/0: ingredient 1 is b-len mem/0: location 1043 is 3 run/0: product 0 is 1 mem/0: storing 1 in location 1044 run/0: instruction string-equal/8 mem/0: location 1044 is 1 run/0: ingredient 0 is 1 run/0: ingredient 1 is run/0: jumping to instruction 10 run/0: instruction string-equal/11 string-equal/0: comparing characters run/0: instruction string-equal/12 run/0: ingredient 0 is 0 mem/0: storing 0 in location 1045 run/0: instruction string-equal/14 run/0: ingredient 0 is i mem/0: location 1045 is 0 run/0: ingredient 1 is a-len mem/0: location 1041 is 3 run/0: product 0 is 0 mem/0: storing 0 in location 1046 run/0: instruction string-equal/15 mem/0: location 1046 is 0 run/0: ingredient 0 is 0 run/0: jump-if fell through run/0: instruction string-equal/16 run/0: ingredient 0 is {name: "a", value: 1, type: 2-5-4, properties: ["a": "address":"array":"character", "deref": ]} mem/0: location 1040 is 1030 run/0: ingredient 1 is {name: "i", value: 6, type: 1, properties: ["i": "integer"]} mem/0: location 1045 is 0 run/0: address to copy is 1031 run/0: its type is 4 mem/0: location 1031 is 97 run/0: product 0 is 97 mem/0: storing 97 in location 1047 run/0: instruction string-equal/17 run/0: ingredient 0 is {name: "b", value: 3, type: 2-5-4, properties: ["b": "address":"array":"character", "deref": ]} mem/0: location 1042 is 1034 run/0: ingredient 1 is {name: "i", value: 6, type: 1, properties: ["i": "integer"]} mem/0: location 1045 is 0 run/0: address to copy is 1035 run/0: its type is 4 mem/0: location 1035 is 97 run/0: product 0 is 97 mem/0: storing 97 in location 1048 run/0: instruction string-equal/19 run/0: ingredient 0 is a2 mem/0: location 1047 is 97 run/0: ingredient 1 is b2 mem/0: location 1048 is 97 run/0: product 0 is 1 mem/0: storing 1 in location 1049 run/0: instruction string-equal/20 mem/0: location 1049 is 1 run/0: ingredient 0 is 1 run/0: ingredient 1 is run/0: jumping to instruction 22 run/0: instruction string-equal/23 run/0: ingredient 0 is i mem/0: location 1045 is 0 run/0: ingredient 1 is 1 run/0: product 0 is 1 mem/0: storing 1 in location 1045 run/0: instruction string-equal/24 run/0: ingredient 0 is -11 run/0: jumping to instruction 14 run/0: instruction string-equal/14 run/0: ingredient 0 is i mem/0: location 1045 is 1 run/0: ingredient 1 is a-len mem/0: location 1041 is 3 run/0: product 0 is 0 mem/0: storing 0 in location 1046 run/0: instruction string-equal/15 mem/0: location 1046 is 0 run/0: ingredient 0 is 0 run/0: jump-if fell through run/0: instruction string-equal/16 run/0: ingredient 0 is {name: "a", value: 1, type: 2-5-4, properties: ["a": "address":"array":"character", "deref": ]} mem/0: location 1040 is 1030 run/0: ingredient 1 is {name: "i", value: 6, type: 1, properties: ["i": "integer"]} mem/0: location 1045 is 1 run/0: address to copy is 1032 run/0: its type is 4 mem/0: location 1032 is 98 run/0: product 0 is 98 mem/0: storing 98 in location 1047 run/0: instruction string-equal/17 run/0: ingredient 0 is {name: "b", value: 3, type: 2-5-4, properties: ["b": "address":"array":"character", "deref": ]} mem/0: location 1042 is 1034 run/0: ingredient 1 is {name: "i", value: 6, type: 1, properties: ["i": "integer"]} mem/0: location 1045 is 1 run/0: address to copy is 1036 run/0: its type is 4 mem/0: location 1036 is 98 run/0: product 0 is 98 mem/0: storing 98 in location 1048 run/0: instruction string-equal/19 run/0: ingredient 0 is a2 mem/0: location 1047 is 98 run/0: ingredient 1 is b2 mem/0: location 1048 is 98 run/0: product 0 is 1 mem/0: storing 1 in location 1049 run/0: instruction string-equal/20 mem/0: location 1049 is 1 run/0: ingredient 0 is 1 run/0: ingredient 1 is run/0: jumping to instruction 22 run/0: instruction string-equal/23 run/0: ingredient 0 is i mem/0: location 1045 is 1 run/0: ingredient 1 is 1 run/0: product 0 is 2 mem/0: storing 2 in location 1045 run/0: instruction string-equal/24 run/0: ingredient 0 is -11 run/0: jumping to instruction 14 run/0: instruction string-equal/14 run/0: ingredient 0 is i mem/0: location 1045 is 2 run/0: ingredient 1 is a-len mem/0: location 1041 is 3 run/0: product 0 is 0 mem/0: storing 0 in location 1046 run/0: instruction string-equal/15 mem/0: location 1046 is 0 run/0: ingredient 0 is 0 run/0: jump-if fell through run/0: instruction string-equal/16 run/0: ingredient 0 is {name: "a", value: 1, type: 2-5-4, properties: ["a": "address":"array":"character", "deref": ]} mem/0: location 1040 is 1030 run/0: ingredient 1 is {name: "i", value: 6, type: 1, properties: ["i": "integer"]} mem/0: location 1045 is 2 run/0: address to copy is 1033 run/0: its type is 4 mem/0: location 1033 is 99 run/0: product 0 is 99 mem/0: storing 99 in location 1047 run/0: instruction string-equal/17 run/0: ingredient 0 is {name: "b", value: 3, type: 2-5-4, properties: ["b": "address":"array":"character", "deref": ]} mem/0: location 1042 is 1034 run/0: ingredient 1 is {name: "i", value: 6, type: 1, properties: ["i": "integer"]} mem/0: location 1045 is 2 run/0: address to copy is 1037 run/0: its type is 4 mem/0: location 1037 is 100 run/0: product 0 is 100 mem/0: storing 100 in location 1048 run/0: instruction string-equal/19 run/0: ingredient 0 is a2 mem/0: location 1047 is 99 run/0: ingredient 1 is b2 mem/0: location 1048 is 100 run/0: product 0 is 0 mem/0: storing 0 in location 1049 run/0: instruction string-equal/20 mem/0: location 1049 is 0 run/0: ingredient 0 is 0 run/0: jump-if fell through run/0: instruction string-equal/21 run/0: result 0 is 0 mem/0: storing 0 in location 3