Skip to content

Commit 74d4e2a

Browse files
committed
Add compile-fail tests for interfaces/impls
Closes #1475
1 parent d01e7cd commit 74d4e2a

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

src/comp/middle/typeck.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,25 +1589,25 @@ fn lookup_method(fcx: @fn_ctxt, expr: @ast::expr, node_id: ast::node_id,
15891589
let substs = substs, n_tps = vec::len(substs), n_tys = vec::len(tps);
15901590
let has_self = ty::type_has_params(fty);
15911591
if method_n_tps + n_tps > 0u {
1592-
if n_tys > 0u {
1592+
if n_tys == 0u || n_tys != method_n_tps {
15931593
if n_tys != method_n_tps {
1594-
tcx.sess.span_fatal
1594+
tcx.sess.span_err
15951595
(expr.span, "incorrect number of type \
15961596
parameters given for this method");
15971597

15981598
}
1599-
substs += tps;
1600-
} else {
16011599
substs += vec::init_fn(method_n_tps, {|_i|
16021600
ty::mk_var(tcx, next_ty_var_id(fcx))
16031601
});
1604-
};
1602+
} else {
1603+
substs += tps;
1604+
}
16051605
write_ty_substs(tcx, node_id, fty, substs);
1606-
} else if n_tys > 0u {
1607-
tcx.sess.span_fatal(expr.span,
1608-
"this method does not take type \
1609-
parameters");
16101606
} else {
1607+
if n_tys > 0u {
1608+
tcx.sess.span_err(expr.span, "this method does not take type \
1609+
parameters");
1610+
}
16111611
write_ty(tcx, node_id, fty);
16121612
}
16131613
if has_self && !option::is_none(self_sub) {

src/test/compile-fail/iface-test-2.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
iface bar { fn dup() -> self; fn blah<X>(); }
2+
impl of bar for int { fn dup() -> int { self } fn blah<X>() {} }
3+
impl of bar for uint { fn dup() -> uint { self } fn blah<X>() {} }
4+
impl of bar for uint { fn dup() -> uint { self } fn blah<X>() {} }
5+
6+
fn main() {
7+
10.dup::<int>(); //! ERROR does not take type parameters
8+
10.blah::<int, int>(); //! ERROR incorrect number of type parameters
9+
10u.dup(); //! ERROR multiple applicable methods
10+
(10 as bar).dup(); //! ERROR contains a self type
11+
}

src/test/compile-fail/iface-test.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
iface foo { fn foo(); }
2+
3+
impl of foo for uint {} //! ERROR missing method `foo`
4+
5+
impl of foo for uint { fn foo() -> int {} } //! ERROR incompatible type
6+
7+
impl of int for uint { fn foo() {} } //! ERROR can only implement interface
8+
9+
fn main() {}

0 commit comments

Comments
 (0)