about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-02-10 13:31:33 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-02-10 13:31:33 +0100
commit74d4e2a32ed28bf2272b1ba3246246557ec6d987 (patch)
tree5461052fa17fdca5746f85365c94bac31e67f67f
parentd01e7cd3406e612f363f95d44291839fc53640d1 (diff)
downloadrust-74d4e2a32ed28bf2272b1ba3246246557ec6d987.tar.gz
rust-74d4e2a32ed28bf2272b1ba3246246557ec6d987.zip
Add compile-fail tests for interfaces/impls
Closes #1475
-rw-r--r--src/comp/middle/typeck.rs18
-rw-r--r--src/test/compile-fail/iface-test-2.rs11
-rw-r--r--src/test/compile-fail/iface-test.rs9
3 files changed, 29 insertions, 9 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 1539b4f8af6..59f65bb0408 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 00000000000..96e5979084e
--- /dev/null
+++ b/src/test/compile-fail/iface-test-2.rs
@@ -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
+}
diff --git a/src/test/compile-fail/iface-test.rs b/src/test/compile-fail/iface-test.rs
new file mode 100644
index 00000000000..86c5a478d81
--- /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() {}