Open hamidb80 opened 3 years ago
new investigation:
import sugar
func makeSlice(slice: HSlice[int ,int]): auto =
slice
let a = 1..2
let ranges = collect newseq:
for i in 0..10:
# a # works [7]
# makeSlice 1 .. 2 # works [8]
1 .. 2 # doesn't work [9]
Output of collect looks ok:
var collectResult_402653193 = initTable[typeof do:
for word in document:
2, typeof do:
for word in document:
word[0 .. 2]]()
for word in document:
collectResult_402653193[2] = word[0 .. 2]
collectResult_402653193
this echo typeof "this"[0..2]
outputs char
...also
echo typeof(1..2)
int
echo typeof(1..2) == int
works as intended. Because ..
has iterators and procs overloads and the iterator one is preferred by default.
Use typeof(1..2, typeOfProc)
to get HSlice[int, int]
.
I cannot fix it, I added bindSym"typeOfProc"
to the calls of typeof but this doesn't work:
let ranges = block:
var collectResult_570425399 = newseq[typeof(
for i in 0 .. 10: 1 .. 2, typeOfProc)]()
for i in 0 .. 10:
collectResult_570425399.add(1 .. 2)
collectResult_570425399
Error: expression '1 .. 2' is of type 'HSlice[system.int, system.int]' and has to be used (or discarded)
Actually everything breaks if you make it typeOfProc
.
typeof
with typeOfProc
doesn't support for
expressions because the compiler just doesn't pass the typeof
flag which is required for for
expressions..
the compiler gives type mismatch error for slicing in
collect
macroExample
Current Output
compiler error for [4]
compiler error for [6]:
Expected Output
compiles successfully
Additional Information
maybe related to #12383
my environment: