1
0
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:
Delyan Angelov 2022-11-22 13:42:29 +02:00
parent cc7e6006f9
commit 7d57559b70
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 3 additions and 3 deletions

View File

@ -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
pub fn (mut list DoublyLinkedList<T>) insert(idx int, item T) ? {
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 {
// new head
list.push_front(item)

View File

@ -58,7 +58,7 @@ pub fn (list LinkedList<T>) index(idx int) ?T {
if iterations == idx {
return node.data
} 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
pub fn (mut list LinkedList<T>) insert(idx int, item T) ? {
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 {
list.push(item)
} else {