Skip to content

Commit 9eb798e

Browse files
committed
Change arg typechecking procedure to make blocks more useful.
1 parent d68f1a8 commit 9eb798e

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/comp/middle/typeck.rs

+28-11
Original file line numberDiff line numberDiff line change
@@ -1611,21 +1611,38 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr,
16111611
}
16121612

16131613
// Check the arguments.
1614-
let i = 0u;
1615-
for a_opt: option::t[@ast::expr] in args {
1616-
alt a_opt {
1617-
some(a) {
1618-
bot |= check_expr_with_unifier(fcx, a, demand::block_coerce,
1619-
arg_tys.(i).ty);
1620-
}
1621-
none. { }
1614+
// We do this in a pretty awful way: first we typecheck any arguments
1615+
// that are not anonymous functions, then we typecheck the anonymous
1616+
// functions. This is so that we have more information about the types
1617+
// of arguments when we typecheck the functions. This isn't really the
1618+
// right way to do this.
1619+
let check_args = lambda(check_blocks: bool) -> bool {
1620+
let i = 0u;
1621+
let bot = false;
1622+
for a_opt: option::t[@ast::expr] in args {
1623+
alt a_opt {
1624+
some(a) {
1625+
let is_block =
1626+
alt a.node { ast::expr_fn(_) { true } _ { false } };
1627+
if is_block == check_blocks {
1628+
bot |= check_expr_with_unifier(fcx, a,
1629+
demand::block_coerce,
1630+
arg_tys.(i).ty);
1631+
}
1632+
}
1633+
none. {}
1634+
}
1635+
i += 1u;
16221636
}
1623-
i += 1u;
1624-
}
1637+
ret bot;
1638+
};
1639+
bot |= check_args(false);
1640+
bot |= check_args(true);
1641+
16251642
ret bot;
16261643
}
1627-
// A generic function for checking assignment expressions
16281644

1645+
// A generic function for checking assignment expressions
16291646
fn check_assignment(fcx: &@fn_ctxt, sp: &span, lhs: &@ast::expr,
16301647
rhs: &@ast::expr, id: &ast::node_id) -> bool {
16311648
let t = next_ty_var(fcx);

0 commit comments

Comments
 (0)