-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Array.slice() negative end inconsistent with other languages (off by one) #56661
Labels
Milestone
Comments
This was referenced Jan 10, 2022
After discussion with @KoBeWi and @timothyqiu, it seems like making the function more permissive on possible values for
I'll give this a try and make a draft PR, we'll see if it's a good idea. |
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Godot version
4.0.dev (d746475)
System information
Linux, Mageia 9 x86_64
Issue description
Follow-up to PR #35901 and issue #53495.
The behavior of the negative
end
parameter forArray.slice()
seems inconsistent with how it behaves in other languages. Our implementation uses:And this
+ 1
adds an inconsistency with other implementations.GDScript
prints:
Python / numpy
prints:
JavaScript
prints:
We can easily remove the
+1
but then the question is how to make it easy to go frombegin
to the size of the original array without repeatingarr.size()
.Making the
end
argument optional like in JavaScript could be an option, but I'm not sure it's easily doable in GDScript. Aside from turning theint end
intoVariant end
, we can't easily make itnull
or use another state to indicate the "go to size()" function.0
would be a validend
for an empty slice, and-1
should behave likesize() - 1
(wraps around).And binding a
slice(int begin)
method is not possible either without polymorphism AFAIK.Steps to reproduce
Expected:
but got:
Minimal reproduction project
See above.
The text was updated successfully, but these errors were encountered: