You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Confirmed on Linux latest devel.
Works OK if replacing openarray by seq
However, I not so sure you are supposed to use openarray like that. here is the generated C code.
// code for test(a: seq[int], b: var openarray[int])-N_NIMCALL(void, test_94003_1385730820)(TY94083*a0, NI*b0, NIb0Len0)
// code for test(a: seq[int], b: var seq[int])+N_NIMCALL(void, test_94003_1385730820)(TY94083*a0, TY94083**b0)
}
As you can see an openarray is literally a pointer to the data, and a size. It doen't care what the original object was, and so I pretty sure you are not supposed to assign a seq or a string to it directly.
I think this should be a compile time error.
You might, however, assign data to to its slice with something like this.
proc`[]=`[T](s: varopenarray[T]; x: Slice[int]; b: openarray[T]) =assert(x.a <= s.high and x.b <= s.high)
var idx =0for i in x.a..x.b:
s[i] = b[idx]
inc(idx)
proctest(a: seq[int], b: varopenarray[int]) =# assign to openarray slice. original data must be at least slice size.
b[0..4] = a[0..4]
In this example the output is incorrect, it is
@[5, 5, 0, 1, 2, 3, 4, 0, 0, 0]
but it should be@[0, 1, 2, 3, 4]
.Nim Compiler Version 0.13.1 (2016-05-13) [MacOSX: amd64]
The text was updated successfully, but these errors were encountered: