|
| 1 | +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +// xfail-test |
| 12 | +enum Nil {Nil} |
| 13 | +struct Cons<T> {head:int, tail:T} |
| 14 | +trait Dot {fn dot(other:self) -> int;} |
| 15 | +impl Nil:Dot { |
| 16 | + fn dot(_:Nil) -> int {0} |
| 17 | +} |
| 18 | +impl<T:Dot> Cons<T>:Dot { |
| 19 | + fn dot(other:Cons<T>) -> int { |
| 20 | + self.head * other.head + self.tail.dot(other.tail) |
| 21 | + } |
| 22 | +} |
| 23 | +fn test<T:Dot> (n:int, i:int, first:T, second:T) ->int { |
| 24 | + match n { |
| 25 | + 0 => {first.dot(second)} |
| 26 | + // Error message should be here. It should be a type error |
| 27 | + // to instantiate `test` at a type other than T. (See #4287) |
| 28 | + _ => {test (n-1, i+1, Cons {head:2*i+1, tail:first}, Cons{head:i*i, tail:second})} |
| 29 | + } |
| 30 | +} |
| 31 | +fn main() { |
| 32 | + let n = test(1, 0, Nil, Nil); |
| 33 | + io::println(fmt!("%d", n)); |
| 34 | +} |
0 commit comments