diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 1539b4f8af6b..59f65bb04084 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1589,25 +1589,25 @@ fn lookup_method(fcx: @fn_ctxt, expr: @ast::expr, node_id: ast::node_id, let substs = substs, n_tps = vec::len(substs), n_tys = vec::len(tps); let has_self = ty::type_has_params(fty); if method_n_tps + n_tps > 0u { - if n_tys > 0u { + if n_tys == 0u || n_tys != method_n_tps { if n_tys != method_n_tps { - tcx.sess.span_fatal + tcx.sess.span_err (expr.span, "incorrect number of type \ parameters given for this method"); } - substs += tps; - } else { substs += vec::init_fn(method_n_tps, {|_i| ty::mk_var(tcx, next_ty_var_id(fcx)) }); - }; + } else { + substs += tps; + } write_ty_substs(tcx, node_id, fty, substs); - } else if n_tys > 0u { - tcx.sess.span_fatal(expr.span, - "this method does not take type \ - parameters"); } else { + if n_tys > 0u { + tcx.sess.span_err(expr.span, "this method does not take type \ + parameters"); + } write_ty(tcx, node_id, fty); } if has_self && !option::is_none(self_sub) { diff --git a/src/test/compile-fail/iface-test-2.rs b/src/test/compile-fail/iface-test-2.rs new file mode 100644 index 000000000000..96e5979084e7 --- /dev/null +++ b/src/test/compile-fail/iface-test-2.rs @@ -0,0 +1,11 @@ +iface bar { fn dup() -> self; fn blah(); } +impl of bar for int { fn dup() -> int { self } fn blah() {} } +impl of bar for uint { fn dup() -> uint { self } fn blah() {} } +impl of bar for uint { fn dup() -> uint { self } fn blah() {} } + +fn main() { + 10.dup::(); //! ERROR does not take type parameters + 10.blah::(); //! ERROR incorrect number of type parameters + 10u.dup(); //! ERROR multiple applicable methods + (10 as bar).dup(); //! ERROR contains a self type +} diff --git a/src/test/compile-fail/iface-test.rs b/src/test/compile-fail/iface-test.rs new file mode 100644 index 000000000000..86c5a478d81e --- /dev/null +++ b/src/test/compile-fail/iface-test.rs @@ -0,0 +1,9 @@ +iface foo { fn foo(); } + +impl of foo for uint {} //! ERROR missing method `foo` + +impl of foo for uint { fn foo() -> int {} } //! ERROR incompatible type + +impl of int for uint { fn foo() {} } //! ERROR can only implement interface + +fn main() {}