diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index aa4012616d1..961f41f5053 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -234,6 +234,7 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t { } fn instantiate(&ty::ctxt tcx, + &span sp, &ty_getter getter, &ast::def_id id, &vec[@ast::ty] args) -> ty::t { @@ -246,13 +247,18 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t { // The typedef is type-parametric. Do the type substitution. // - // TODO: Make sure the number of supplied bindings matches the number - // of type parameters in the typedef. Emit a friendly error otherwise. let vec[ty::t] param_bindings = []; for (@ast::ty ast_ty in args) { param_bindings += [ast_ty_to_ty(tcx, getter, ast_ty)]; } + if (vec::len(param_bindings) != + ty::count_ty_params(tcx, params_opt_and_ty._1)) { + tcx.sess.span_err(sp, "Wrong number of type arguments for a" + + " polymorphic tag"); + } + + auto typ = ty::substitute_type_params(tcx, param_bindings, params_opt_and_ty._1); ret typ; @@ -315,11 +321,13 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t { case (ast::ty_path(?path, ?ann)) { alt (tcx.def_map.get(ann.id)) { case (ast::def_ty(?id)) { - typ = instantiate(tcx, getter, id, path.node.types); + typ = instantiate(tcx, ast_ty.span, getter, id, + path.node.types); } case (ast::def_native_ty(?id)) { typ = getter(id)._1; } case (ast::def_obj(?id)) { - typ = instantiate(tcx, getter, id, path.node.types); + typ = instantiate(tcx, ast_ty.span, getter, id, + path.node.types); } case (ast::def_ty_arg(?id)) { typ = ty::mk_param(tcx, id); } case (_) { diff --git a/src/test/compile-fail/tag-type-args.rs b/src/test/compile-fail/tag-type-args.rs new file mode 100644 index 00000000000..4e890dfadb5 --- /dev/null +++ b/src/test/compile-fail/tag-type-args.rs @@ -0,0 +1,13 @@ +// xfail-stage0 +// error-pattern: Wrong number of type arguments + +tag quux[T] { +} + +fn foo(quux c) -> () { + assert false; +} + +fn main() { + fail; +} \ No newline at end of file