fix: iterator bugs

This commit is contained in:
Shunsuke Shibayama 2023-08-17 20:01:05 +09:00
parent ed245f6c08
commit efcf23b04d
4 changed files with 18 additions and 2 deletions

View file

@ -1761,7 +1761,10 @@ impl Context {
let mut enumerate = Self::builtin_poly_class(ENUMERATE, vec![PS::t_nd(TY_T)], 2);
enumerate.register_superclass(Obj, &obj);
enumerate
.register_marker_trait(self, poly(ITERABLE, vec![ty_tp(T.clone())]))
.register_marker_trait(
self,
poly(ITERABLE, vec![ty_tp(tuple_t(vec![Nat, T.clone()]))]),
)
.unwrap();
enumerate
.register_marker_trait(self, poly(OUTPUT, vec![ty_tp(T.clone())]))

View file

@ -77,7 +77,7 @@ impl Context {
.quantify();
let t_filter = nd_func(
vec![
kw(KW_FUNC, nd_func(vec![anon(T.clone())], None, T.clone())),
kw(KW_FUNC, nd_func(vec![anon(T.clone())], None, Bool)),
kw(KW_ITERABLE, poly(ITERABLE, vec![ty_tp(T.clone())])),
],
None,

View file

@ -0,0 +1,8 @@
for! enumerate(0..3), ((i, j),) =>
assert i == j
for! zip(0..3, 0..3), ((i, j),) =>
assert i == j
for! filter(x -> x > 1, 0..3), i =>
assert i > 1
for! map(x -> "\{x}", [1, 2, 3]), s =>
assert str(s) == s

View file

@ -394,6 +394,11 @@ fn exec_invalid_param() -> Result<(), ()> {
expect_failure("tests/should_err/invalid_param.er", 0, 3)
}
#[test]
fn exec_iterator() -> Result<(), ()> {
expect_success("tests/should_ok/iterator.er", 0)
}
#[test]
fn exec_move_check() -> Result<(), ()> {
expect_failure("examples/move_check.er", 1, 1)