Skip to content

Commit

Permalink
frontend: Fix enumerate() test case for Array and Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Feb 7, 2025
1 parent 700b7b9 commit 914d74e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions dora-frontend/src/specialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ pub fn specialize_ty_for_call(
.get(&assoc_id)
.map(|a| sa.alias(*a).ty())
.unwrap_or(SourceType::Error);
let ty = specialize_type(sa, ty, &impl_match.bindings);
specialize_ty_for_call(sa, ty, caller_element, call_data)
} else {
unimplemented!()
Expand Down
30 changes: 17 additions & 13 deletions tests/stdlib/iterator-enumerate.dora
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ use std::collections::{HashMap, VecIter};
use std::traits::Enumerate;

fn main() {
let x = Vec[Int]::new(1, 2, 3, 4, 5);
let it1: VecIter[Int] = x.iter();
let it: Enumerate[VecIter[Int]] = it1.enumerate();
assert(Some[(Int, Int)]((0, 1)) == it.next());
assert(Some[(Int, Int)]((1, 2)) == it.next());
assert(Some[(Int, Int)]((2, 3)) == it.next());
assert(Some[(Int, Int)]((3, 4)) == it.next());
assert(Some[(Int, Int)]((4, 5)) == it.next());
assert(it.next() is None);
let x = Vec[Int]::new(1, 2, 3, 4, 5).iter().enumerate();
assert(Some[(Int, Int)]((0, 1)) == x.next());
assert(Some[(Int, Int)]((1, 2)) == x.next());
assert(Some[(Int, Int)]((2, 3)) == x.next());
assert(Some[(Int, Int)]((3, 4)) == x.next());
assert(Some[(Int, Int)]((4, 5)) == x.next());
assert(x.next() is None);

// let x = Array[Int]::new(1, 2, 3, 4, 5);
// assert(x.iter().count() == 5);
let x = Array[String]::new("one", "two", "three").iter().enumerate();
assert(Some[(Int, String)]((0, "one")) == x.next());
assert(Some[(Int, String)]((1, "two")) == x.next());
assert(Some[(Int, String)]((2, "three")) == x.next());
assert(x.next() is None);

// let x = HashMap[Int, String]::new((1, "one"), (2, "two"), (3, "three"));
// assert(x.iter().count() == 3);
// let x = HashMap[Int, String]::new((1, "one"), (2, "two"), (3, "three")).iter().enumerate();
// assert(Some[(Int, (Int, String))]((0, (1, "one"))) == x.next());
// assert(Some[(Int, (Int, String))]((1, (2, "two"))) == x.next());
// assert(Some[(Int, (Int, String))]((2, (3, "three"))) == x.next());
// assert(x.next() is None);
}

0 comments on commit 914d74e

Please sign in to comment.