about summary refs log tree commit diff
path: root/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs')
-rw-r--r--src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs b/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs
new file mode 100644
index 00000000000..6cb05516520
--- /dev/null
+++ b/src/test/run-pass/trait-inheritance-cast-without-call-to-supertrait.rs
@@ -0,0 +1,31 @@
+// Testing that we can cast to a subtrait and call subtrait
+// methods. Not testing supertrait methods
+
+trait Foo {
+    fn f() -> int;
+}
+
+trait Bar : Foo {
+    fn g() -> int;
+}
+
+struct A {
+    x: int
+}
+
+impl A : Foo {
+    fn f() -> int { 10 }
+}
+
+impl A : Bar {
+    fn g() -> int { 20 }
+}
+
+fn main() {
+    let a = &A { x: 3 };
+    let afoo = a as &Foo;
+    let abar = a as &Bar;
+    assert afoo.f() == 10;
+    assert abar.g() == 20;
+}
+