Skip to content

std: fix iterator dropping in List eq #244

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

Merged
merged 1 commit into from
May 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/programs/string_ops.vi
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ pub fn main(&io: &IO) {
io.println("{"hello" != "world"}");
io.println("{"hello" == "hello world"}");
io.println("{"world" == "hello world"}");

let x = "hi";
io.println("{x == "xy"}");
io.println("{x == "hi"}");
io.println("{x}");
}
3 changes: 3 additions & 0 deletions tests/snaps/vine/string_ops/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ false
true
false
false
false
true
hi
24 changes: 12 additions & 12 deletions tests/snaps/vine/string_ops/stats.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

Interactions
Total 3_397
Depth 344
Breadth 9
Annihilate 1_517
Total 3_866
Depth 358
Breadth 10
Annihilate 1_752
Commute 0
Copy 471
Erase 522
Expand 296
Call 399
Branch 192
Copy 516
Erase 580
Expand 339
Call 459
Branch 220

Memory
Heap 13_504 B
Allocated 66_224 B
Freed 66_224 B
Heap 15_504 B
Allocated 75_936 B
Freed 75_936 B
10 changes: 6 additions & 4 deletions vine/std/data/List.vi
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ pub mod List {
if a.len() != b.len() {
return false;
}
let a = a.iter();
let b = b.iter();
while a.next() is Some(&a) && b.next() is Some(&b) {
if a != b {
let a_iter = a.iter();
let b_iter = b.iter();
while a_iter.next() is Some(&a_elem) && b_iter.next() is Some(&b_elem) {
if a_elem != b_elem {
a_iter.drop();
b_iter.drop();
return false;
}
}
Expand Down