Skip to content

Commit

Permalink
Output a meaningful error when too few or too many type parameters given
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jul 11, 2011
1 parent 86ee345 commit 5f544b1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,20 @@ fn instantiate_path(&@fn_ctxt fcx, &ast::path pth, &ty_param_count_and_ty tpt,
auto ty_substs_opt;
auto ty_substs_len = ivec::len[@ast::ty](pth.node.types);
if (ty_substs_len > 0u) {
auto param_var_len = ivec::len(ty_param_vars);
if (param_var_len == 0u) {
fcx.ccx.tcx.sess.span_fatal
(sp, "this item does not take type parameters");
} else if (ty_substs_len > param_var_len) {
fcx.ccx.tcx.sess.span_fatal
(sp, "too many type parameter provided for this item");
} else if (ty_substs_len < param_var_len) {
fcx.ccx.tcx.sess.span_fatal
(sp, "not enough type parameters provided for this item");
}
let ty::t[] ty_substs = ~[];
auto i = 0u;
while (i < ty_substs_len) {
// TODO: Report an error if the number of type params in the item
// and the supplied number of type params don't match.

auto ty_var = ty::mk_var(fcx.ccx.tcx, ty_param_vars.(i));
auto ty_subst = ast_ty_to_ty_crate(fcx.ccx, pth.node.types.(i));
auto res_ty = demand::simple(fcx, pth.span, ty_var, ty_subst);
Expand Down

0 comments on commit 5f544b1

Please sign in to comment.