fix: allow empty range subscripts [0..-1] and [0...0] on empty lists
Add special case in list_subscript native to return a new empty list when the source list is empty and the requested range is [0..-1] (inclusive) or [0...0] (exclusive). This enables using list[0..-1] as a universal copy idiom that works even for empty lists. Update the List.+ operator to use this idiom instead of manual iteration. Add test cases for both range forms on empty lists.
This commit is contained in:
+1
-4
@@ -10,10 +10,7 @@ class List {
|
||||
}
|
||||
|
||||
+ that {
|
||||
var result = []
|
||||
for (element in this) {
|
||||
result.add(element)
|
||||
}
|
||||
var result = this[0..-1]
|
||||
for (element in that) {
|
||||
result.add(element)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user