mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
datatypes: make the out of bounds errors for lists APIs more detailed
This commit is contained in:
parent
cc7e6006f9
commit
7d57559b70
@ -124,7 +124,7 @@ pub fn (mut list DoublyLinkedList<T>) pop_front() ?T {
|
|||||||
// insert adds an element to the linked list at the given index
|
// insert adds an element to the linked list at the given index
|
||||||
pub fn (mut list DoublyLinkedList<T>) insert(idx int, item T) ? {
|
pub fn (mut list DoublyLinkedList<T>) insert(idx int, item T) ? {
|
||||||
if idx < 0 || idx > list.len {
|
if idx < 0 || idx > list.len {
|
||||||
return error('Index out of bounds')
|
return error('Index ${idx} out of bounds [0..${list.len}]')
|
||||||
} else if idx == 0 {
|
} else if idx == 0 {
|
||||||
// new head
|
// new head
|
||||||
list.push_front(item)
|
list.push_front(item)
|
||||||
|
@ -58,7 +58,7 @@ pub fn (list LinkedList<T>) index(idx int) ?T {
|
|||||||
if iterations == idx {
|
if iterations == idx {
|
||||||
return node.data
|
return node.data
|
||||||
} else {
|
} else {
|
||||||
return error('Index out of bounds')
|
return error('Index ${idx} != iterations: ${iterations}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ pub fn (mut list LinkedList<T>) shift() ?T {
|
|||||||
// insert adds an element to the linked list at the given index
|
// insert adds an element to the linked list at the given index
|
||||||
pub fn (mut list LinkedList<T>) insert(idx int, item T) ? {
|
pub fn (mut list LinkedList<T>) insert(idx int, item T) ? {
|
||||||
if idx < 0 || idx > list.len {
|
if idx < 0 || idx > list.len {
|
||||||
return error('Index out of bounds')
|
return error('Index ${idx} out of bounds [0..${list.len}]')
|
||||||
} else if list.len == 0 {
|
} else if list.len == 0 {
|
||||||
list.push(item)
|
list.push(item)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user