Skip to content

Commit bdea8d9

Browse files
committed
---
yaml --- r: 2980 b: refs/heads/master c: 7527084 h: refs/heads/master v: v3
1 parent 5b1dc87 commit bdea8d9

File tree

4 files changed

+52
-51
lines changed

4 files changed

+52
-51
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 8691a1a1e5900eaca70415bad0bffdbfe8bd7389
2+
refs/heads/master: 7527084e629340503fbe15b8e21c73879b5bd253

trunk/src/comp/middle/alias.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ fn check_expr(ctx cx, &@ast::expr ex) {
7373
auto i = 0u;
7474
let vec[def_id] listed = [];
7575
for (ty::arg argty in argtys) {
76-
// FIXME Treat mo_either specially here?
7776
if (argty.mode != ty::mo_val) {
7877
alt (check_rooted(cx, args.(i), false)) {
7978
case (some(?did)) {

trunk/src/comp/middle/ty.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import util::data::interner;
4242
tag mode {
4343
mo_val;
4444
mo_alias;
45-
mo_either;
4645
}
4746

4847
type arg = rec(mode mode, t ty);
@@ -486,7 +485,6 @@ fn ty_to_str(&ctxt cx, &t typ) -> str {
486485
alt (input.mode) {
487486
case (mo_val) { s = ""; }
488487
case (mo_alias) { s = "&"; }
489-
case (mo_either) { s = "?"; }
490488
}
491489

492490
ret s + ty_to_str(cx, input.ty);
@@ -1944,13 +1942,9 @@ mod unify {
19441942
auto expected_input = expected_inputs.(i);
19451943
auto actual_input = actual_inputs.(i);
19461944

1947-
// Unify the result modes. "mo_either" unifies with both modes.
1945+
// Unify the result modes.
19481946
auto result_mode;
1949-
if (expected_input.mode == mo_either) {
1950-
result_mode = actual_input.mode;
1951-
} else if (actual_input.mode == mo_either) {
1952-
result_mode = expected_input.mode;
1953-
} else if (expected_input.mode != actual_input.mode) {
1947+
if (expected_input.mode != actual_input.mode) {
19541948
// FIXME this is the wrong error
19551949
ret fn_common_res_err(ures_err(terr_arg_count));
19561950
} else {

trunk/src/comp/middle/typeck.rs

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import middle::ty::field;
1818
import middle::ty::method;
1919
import middle::ty::mo_val;
2020
import middle::ty::mo_alias;
21-
import middle::ty::mo_either;
2221
import middle::ty::node_type_table;
2322
import middle::ty::pat_ty;
2423
import middle::ty::path_to_str;
@@ -1401,52 +1400,60 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
14011400

14021401
// A generic function to factor out common logic from call and bind
14031402
// expressions.
1404-
fn check_call_or_bind(&@fn_ctxt fcx, &@ast::expr f,
1403+
fn check_call_or_bind(&@fn_ctxt fcx, &span sp, &@ast::expr f,
14051404
&vec[option::t[@ast::expr]] args) {
14061405
// Check the function.
14071406
check_expr(fcx, f);
14081407

1409-
// Check the arguments and generate the argument signature.
1410-
let vec[option::t[@ast::expr]] args_0 = [];
1411-
let vec[arg] arg_tys_0 = [];
1408+
// Get the function type. We need to have resolved it enough to know
1409+
// it's a ty_fn or ty_native_fn.
1410+
auto fty = expr_ty(fcx.ccx.tcx, f);
1411+
fty = ty::unify::resolve_all_vars(fcx.ccx.tcx, fcx.var_bindings, fty);
1412+
1413+
// Grab the argument types and the return type.
1414+
auto arg_tys;
1415+
alt (ty::struct(fcx.ccx.tcx, fty)) {
1416+
case (ty::ty_fn(_, ?arg_tys_0, _, _)) {
1417+
arg_tys = arg_tys_0;
1418+
}
1419+
case (ty::ty_native_fn(_, ?arg_tys_0, _)) {
1420+
arg_tys = arg_tys_0;
1421+
}
1422+
case (_) {
1423+
fcx.ccx.tcx.sess.span_err(f.span, "mismatched types: " +
1424+
"expected function or native function but found " +
1425+
ty_to_str(fcx.ccx.tcx, fty));
1426+
}
1427+
}
1428+
1429+
// Check that the correct number of arguments were supplied.
1430+
auto expected_arg_count = vec::len[ty::arg](arg_tys);
1431+
auto supplied_arg_count = vec::len[option::t[@ast::expr]](args);
1432+
if (expected_arg_count != supplied_arg_count) {
1433+
fcx.ccx.tcx.sess.span_err(sp,
1434+
#fmt("this function takes %u parameter%s but %u parameter%s \
1435+
supplied",
1436+
expected_arg_count,
1437+
if (expected_arg_count == 1u) { "" } else { "s" },
1438+
supplied_arg_count,
1439+
if (supplied_arg_count == 1u) { " was" }
1440+
else { "s were" }));
1441+
}
1442+
1443+
// Check the arguments.
1444+
// TODO: iter2
1445+
auto i = 0u;
14121446
for (option::t[@ast::expr] a_opt in args) {
14131447
alt (a_opt) {
14141448
case (some(?a)) {
14151449
check_expr(fcx, a);
1416-
auto typ = expr_ty(fcx.ccx.tcx, a);
1417-
vec::push[arg](arg_tys_0, rec(mode=mo_either, ty=typ));
1450+
demand::simple(fcx, a.span, arg_tys.(i).ty,
1451+
expr_ty(fcx.ccx.tcx, a));
14181452
}
1419-
case (none) {
1420-
auto typ = next_ty_var(fcx);
1421-
vec::push[arg](arg_tys_0, rec(mode=mo_either, ty=typ));
1422-
}
1423-
}
1424-
}
1425-
1426-
auto rt_0 = next_ty_var(fcx);
1427-
auto t_0;
1428-
alt (struct(fcx.ccx.tcx, expr_ty(fcx.ccx.tcx, f))) {
1429-
case (ty::ty_fn(?proto, _, _, ?cf)) {
1430-
t_0 = ty::mk_fn(fcx.ccx.tcx, proto, arg_tys_0, rt_0, cf);
1431-
}
1432-
case (ty::ty_native_fn(?abi, _, _)) {
1433-
t_0 = ty::mk_native_fn(fcx.ccx.tcx, abi, arg_tys_0, rt_0);
1434-
}
1435-
case (?u) {
1436-
fcx.ccx.tcx.sess.span_err(f.span,
1437-
"check_call_or_bind(): fn expr doesn't have fn type,"
1438-
+ " instead having: " +
1439-
ty_to_str(fcx.ccx.tcx,
1440-
expr_ty(fcx.ccx.tcx, f)));
1453+
case (none) { /* no-op */ }
14411454
}
1455+
i += 1u;
14421456
}
1443-
1444-
// Unify the callee and arguments.
1445-
auto f_ty = ty::expr_ty(fcx.ccx.tcx, f);
1446-
auto f_tps = ty::expr_ty_params_and_ty(fcx.ccx.tcx, f)._0;
1447-
auto tpt_1 = demand::full(fcx, f.span, f_ty, t_0, f_tps,
1448-
NO_AUTODEREF);
1449-
//replace_expr_type(fcx, f, tpt_1);
14501457
}
14511458

14521459
// A generic function for checking assignment expressions
@@ -1461,14 +1468,15 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
14611468
}
14621469

14631470
// A generic function for checking call expressions
1464-
fn check_call(&@fn_ctxt fcx, &@ast::expr f, &vec[@ast::expr] args) {
1471+
fn check_call(&@fn_ctxt fcx, &span sp, &@ast::expr f,
1472+
&vec[@ast::expr] args) {
14651473
let vec[option::t[@ast::expr]] args_opt_0 = [];
14661474
for (@ast::expr arg in args) {
14671475
args_opt_0 += [some[@ast::expr](arg)];
14681476
}
14691477

14701478
// Call the generic checker.
1471-
check_call_or_bind(fcx, f, args_opt_0);
1479+
check_call_or_bind(fcx, sp, f, args_opt_0);
14721480
}
14731481

14741482
// A generic function for checking for or for-each loops
@@ -1861,7 +1869,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
18611869

18621870
case (ast::expr_bind(?f, ?args, ?a)) {
18631871
// Call the generic checker.
1864-
check_call_or_bind(fcx, f, args);
1872+
check_call_or_bind(fcx, expr.span, f, args);
18651873

18661874
// Pull the argument and return types out.
18671875
auto proto_1;
@@ -1904,7 +1912,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
19041912
function name onto purity-designation */
19051913
require_pure_call(fcx.ccx, fcx.purity, f, expr.span);
19061914

1907-
check_call(fcx, f, args);
1915+
check_call(fcx, expr.span, f, args);
19081916

19091917
// Pull the return type out of the type of the function.
19101918
auto rt_1 = ty::mk_nil(fcx.ccx.tcx); // FIXME: typestate botch
@@ -1959,7 +1967,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
19591967
}
19601968

19611969
case (ast::expr_spawn(_, _, ?f, ?args, ?a)) {
1962-
check_call(fcx, f, args);
1970+
check_call(fcx, expr.span, f, args);
19631971

19641972
auto fty = expr_ty(fcx.ccx.tcx, f);
19651973
auto ret_ty = ty::ret_ty_of_fn_ty(fcx.ccx.tcx, fty);

0 commit comments

Comments
 (0)