Add compile-fail tests for interfaces/impls

Closes #1475
This commit is contained in:
Marijn Haverbeke 2012-02-10 13:31:33 +01:00
parent d01e7cd340
commit 74d4e2a32e
3 changed files with 29 additions and 9 deletions

View file

@ -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) {

View file

@ -0,0 +1,11 @@
iface bar { fn dup() -> self; fn blah<X>(); }
impl of bar for int { fn dup() -> int { self } fn blah<X>() {} }
impl of bar for uint { fn dup() -> uint { self } fn blah<X>() {} }
impl of bar for uint { fn dup() -> uint { self } fn blah<X>() {} }
fn main() {
10.dup::<int>(); //! ERROR does not take type parameters
10.blah::<int, int>(); //! ERROR incorrect number of type parameters
10u.dup(); //! ERROR multiple applicable methods
(10 as bar).dup(); //! ERROR contains a self type
}

View file

@ -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() {}