-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't create empty openArray with int8 #23752
Comments
Just echo v.toOpenArray(0, -1) |
The parameter type of Converting |
I wish the API had it so that the second argument was the length of the openarray, not the end index, that would probably make more sense for the construction of the openarray too since it stores the length. For the start/end index version we could have overloaded it for It's not really needed to fix this issue but we could still add an overload like v.toOpenArrayLen(0'i8, 0) |
the sanity ship of slice indexing in nim sailed, so we must do with what we have unfortunately. an empty array is
it's a lot more dangerous at runtime: var v: int
var v8: int8
var a: array[1, byte]
echo a.toOpenArray(v, v-1)
echo a.toOpenArray(v8, v8-1) # crashes here - obviously you should be able to use int8 like this. |
@arnetheduck var v: int
var a: array[1, byte]
echo a.toOpenArray(v, v-1) So when implementing a proc toOpenArray2*[I, T](x: array[I, T]; first, last: I) =
echo x
proc foo =
var v: array[1, byte]
toOpenArray2(v, 0, -1)
foo() It gives |
I'm not sure I understand your comment.
See https://play.nim-lang.org/#pasty=dAQERzuy
we can see the empty openArray being printed, then the crash happening - it should have the same behavior regardless of int type. |
I explained why this happens. I'm not saying the API is reasonable. proc toOpenArray*[I, T](x: array[I, T]; first, last: I): openArray[T] {.
magic: "Slice".} Isn't It is consistent with
|
I think there is no type resolution bug here but the code generation for some variant of |
Description
at runtime, this crashes with a Defect (!)
Nim Version
2.0.6
Current Output
Expected Output
No response
Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: