Skip to content

Commit

Permalink
Add compile-fail tests for interfaces/impls
Browse files Browse the repository at this point in the history
Closes #1475
  • Loading branch information
marijnh committed Feb 10, 2012
1 parent d01e7cd commit 74d4e2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/test/compile-fail/iface-test-2.rs
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions src/test/compile-fail/iface-test.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 74d4e2a

Please sign in to comment.