Skip to content

Commit 07225e2

Browse files
committed
Make a call with the wrong number of arguments non-fatal. Closes #784.
1 parent 8373422 commit 07225e2

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/comp/middle/typeck.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,35 +1573,37 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr,
15731573
}
15741574

15751575
// Grab the argument types
1576-
let arg_tys;
1577-
alt sty {
1578-
ty::ty_fn(_, arg_tys_0, _, _, _) |
1579-
ty::ty_native_fn(_, arg_tys_0, _) { arg_tys = arg_tys_0; }
1576+
let arg_tys = alt sty {
1577+
ty::ty_fn(_, arg_tys, _, _, _) |
1578+
ty::ty_native_fn(_, arg_tys, _) { arg_tys }
15801579
_ {
15811580
fcx.ccx.tcx.sess.span_fatal(f.span,
15821581
"mismatched types: \
15831582
expected function or native \
15841583
function but found "
1585-
+ ty_to_str(fcx.ccx.tcx, fty));
1584+
+ ty_to_str(fcx.ccx.tcx, fty))
15861585
}
1587-
}
1586+
};
15881587

15891588
// Check that the correct number of arguments were supplied.
1590-
let expected_arg_count = vec::len::<ty::arg>(arg_tys);
1591-
let supplied_arg_count = vec::len::<option::t<@ast::expr>>(args);
1589+
let expected_arg_count = vec::len(arg_tys);
1590+
let supplied_arg_count = vec::len(args);
15921591
if expected_arg_count != supplied_arg_count {
1593-
fcx.ccx.tcx.sess.span_fatal(sp,
1594-
#fmt("this function takes %u \
1595-
parameter%s but %u parameter%s \
1596-
supplied",
1597-
expected_arg_count,
1598-
if expected_arg_count == 1u {
1599-
""
1600-
} else { "s" },
1601-
supplied_arg_count,
1602-
if supplied_arg_count == 1u {
1603-
" was"
1604-
} else { "s were" }));
1592+
fcx.ccx.tcx.sess.span_err(
1593+
sp,
1594+
#fmt("this function takes %u \
1595+
parameter%s but %u parameter%s supplied",
1596+
expected_arg_count,
1597+
if expected_arg_count == 1u { "" } else { "s" },
1598+
supplied_arg_count,
1599+
if supplied_arg_count == 1u
1600+
{ " was" } else { "s were" }));
1601+
// HACK: extend the arguments list with dummy arguments to
1602+
// check against
1603+
let dummy = {mode: ty::mo_val, ty: ty::mk_nil(fcx.ccx.tcx)};
1604+
while vec::len(arg_tys) < supplied_arg_count {
1605+
arg_tys += ~[dummy];
1606+
}
16051607
}
16061608

16071609
// Check the arguments.

0 commit comments

Comments
 (0)