Skip to content

Commit a7e559e

Browse files
committed
Fix polymorphic iterators. Closes #829.
1 parent cc2ebbe commit a7e559e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/comp/middle/trans.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3737,8 +3737,7 @@ fn trans_for_each(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
37373737
ast::expr_call(f, args) {
37383738
let pair =
37393739
create_real_fn_pair(cx, iter_body_llty, lliterbody, llenv.ptr);
3740-
r = trans_call(cx, f, some::<ValueRef>(cx.build.Load(pair)), args,
3741-
seq.id);
3740+
r = trans_call(cx, f, some(pair), args, seq.id);
37423741
ret rslt(r.bcx, C_nil());
37433742
}
37443743
}
@@ -4626,7 +4625,17 @@ fn trans_args(cx: &@block_ctxt, llenv: ValueRef,
46264625
llargs += lltydescs;
46274626

46284627
// ... then possibly an lliterbody argument.
4629-
alt lliterbody { none. { } some(lli) { llargs += ~[lli]; } }
4628+
alt lliterbody {
4629+
none. { }
4630+
some(lli) {
4631+
let lli = if (ty::type_contains_params(bcx_tcx(cx), retty)) {
4632+
let body_ty = ty::mk_iter_body_fn(bcx_tcx(cx), retty);
4633+
let body_llty = type_of_inner(bcx_ccx(cx), cx.sp, body_ty);
4634+
bcx.build.PointerCast(lli, T_ptr(body_llty))
4635+
} else { lli };
4636+
llargs += ~[cx.build.Load(lli)];
4637+
}
4638+
}
46304639

46314640
// ... then explicit args.
46324641

src/test/run-pass/polymorphic-iter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
iter iter2<@T>() -> T { }
2+
fn main() {
3+
for each i: int in iter2() { }
4+
}

0 commit comments

Comments
 (0)