Skip to content

Commit 5f544b1

Browse files
committed
Output a meaningful error when too few or too many type parameters given
Closes #619
1 parent 86ee345 commit 5f544b1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/comp/middle/typeck.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,20 @@ fn instantiate_path(&@fn_ctxt fcx, &ast::path pth, &ty_param_count_and_ty tpt,
159159
auto ty_substs_opt;
160160
auto ty_substs_len = ivec::len[@ast::ty](pth.node.types);
161161
if (ty_substs_len > 0u) {
162+
auto param_var_len = ivec::len(ty_param_vars);
163+
if (param_var_len == 0u) {
164+
fcx.ccx.tcx.sess.span_fatal
165+
(sp, "this item does not take type parameters");
166+
} else if (ty_substs_len > param_var_len) {
167+
fcx.ccx.tcx.sess.span_fatal
168+
(sp, "too many type parameter provided for this item");
169+
} else if (ty_substs_len < param_var_len) {
170+
fcx.ccx.tcx.sess.span_fatal
171+
(sp, "not enough type parameters provided for this item");
172+
}
162173
let ty::t[] ty_substs = ~[];
163174
auto i = 0u;
164175
while (i < ty_substs_len) {
165-
// TODO: Report an error if the number of type params in the item
166-
// and the supplied number of type params don't match.
167-
168176
auto ty_var = ty::mk_var(fcx.ccx.tcx, ty_param_vars.(i));
169177
auto ty_subst = ast_ty_to_ty_crate(fcx.ccx, pth.node.types.(i));
170178
auto res_ty = demand::simple(fcx, pth.span, ty_var, ty_subst);

0 commit comments

Comments
 (0)