From 07225e2169d3a96bed28110ff976a6752c0ec0a8 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Tue, 16 Aug 2011 16:39:30 -0700 Subject: [PATCH] Make a call with the wrong number of arguments non-fatal. Closes #784. --- src/comp/middle/typeck.rs | 42 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 32a834b56035..d2e4639618d4 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1573,35 +1573,37 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, } // Grab the argument types - let arg_tys; - alt sty { - ty::ty_fn(_, arg_tys_0, _, _, _) | - ty::ty_native_fn(_, arg_tys_0, _) { arg_tys = arg_tys_0; } + let arg_tys = alt sty { + ty::ty_fn(_, arg_tys, _, _, _) | + ty::ty_native_fn(_, arg_tys, _) { arg_tys } _ { fcx.ccx.tcx.sess.span_fatal(f.span, "mismatched types: \ expected function or native \ function but found " - + ty_to_str(fcx.ccx.tcx, fty)); + + ty_to_str(fcx.ccx.tcx, fty)) } - } + }; // Check that the correct number of arguments were supplied. - let expected_arg_count = vec::len::(arg_tys); - let supplied_arg_count = vec::len::>(args); + let expected_arg_count = vec::len(arg_tys); + let supplied_arg_count = vec::len(args); if expected_arg_count != supplied_arg_count { - fcx.ccx.tcx.sess.span_fatal(sp, - #fmt("this function takes %u \ - parameter%s but %u parameter%s \ - supplied", - expected_arg_count, - if expected_arg_count == 1u { - "" - } else { "s" }, - supplied_arg_count, - if supplied_arg_count == 1u { - " was" - } else { "s were" })); + fcx.ccx.tcx.sess.span_err( + sp, + #fmt("this function takes %u \ + parameter%s but %u parameter%s supplied", + expected_arg_count, + if expected_arg_count == 1u { "" } else { "s" }, + supplied_arg_count, + if supplied_arg_count == 1u + { " was" } else { "s were" })); + // HACK: extend the arguments list with dummy arguments to + // check against + let dummy = {mode: ty::mo_val, ty: ty::mk_nil(fcx.ccx.tcx)}; + while vec::len(arg_tys) < supplied_arg_count { + arg_tys += ~[dummy]; + } } // Check the arguments.