pub type Color { Red, Green } impl Show { fn show :: c { match c { Red -> "red", Green -> "green" } } } pub fn shown :: -> String { show Red } pub type Point { Point(x: Int, y: Int) } impl Eq { fn eq :: a b { a.x == b.x && a.y == b.y } fn extra :: //~ ERROR E0406 not a method of trait `Eq` a { a } } impl Show //~ ERROR E0407 missing method `show` {} impl Show {} //~ ERROR E0404 implemented more than once pub fn no_impl :: -> Bool { (fn x { x }) == (fn x { x }) //~ ERROR E0401 does not implement `Eq` } pub fn nested_no_impl :: f: fn() -> Int -> String { show //~^ ERROR E0401 `fn() -> Int` does not implement `Show` (needed for `Show Int>>`) [f] } @derive Eq Show pub type Pair { Pair(a, a) } pub fn derived :: p: Pair -> Bool { p == Pair(1, 2) } @derive Eq pub type Holder //~ ERROR E0410 field of type `fn(Int) -> Int` { Holder(fn(Int) -> Int) } @derive Clone pub type Uncloneable //~ ERROR E0408 cannot be derived { Uncloneable } impl Eq> {} //~ ERROR E0409 distinct type variables fn ambiguous :: { show (todo ()) //~ ERROR E0403 cannot tell } fn todo :: { todo () } // `<>` needs `Semigroup` (ADR 0027): Ints have none, and both sides have // one type. fn add_digits :: { 1 <> 2 //~ ERROR E0401 `Int` does not implement `Semigroup` } fn mixed :: { "a" <> 1 //~ ERROR E0202 expected `String`, found `Int` }