// Edge cases a sound checker must get right. // Rigid variables are distinct from each other. pub fn coerce :: x: a -> b { x //~ ERROR E0202 expected `b`, found `a` } // A generalized function can be used at several types... fn ident :: x { x } fn two_uses :: { (ident 1, ident "a") } //~ TYPE two_uses: fn() -> (Int, String) // ...but within its own recursive group it is monomorphic. fn ping :: n { pong n } fn pong :: n { let s = ping "x" ping 1 //~ ERROR E0202 expected `String`, found `Int` } // Constraints flow through impls with `where` clauses. pub type Box { Box(a) } impl Show> where Show { fn show :: b { match b { Box(x) -> "Box(" <> show x <> ")" } } } pub fn show_box :: b: Box -> String { show b } pub fn show_fn_box :: b: Box Int> -> String { show //~^ ERROR E0401 `fn() -> Int` does not implement `Show` (needed for `Show Int>>`) b } pub type Wrap { Wrap(a) } impl Show> { fn show :: w { match w { Wrap(x) -> show x //~ ERROR E0402 `a` is not known to implement `Show` } } } // An inferred constraint is satisfied at a concrete call site. fn render :: x { "<" <> show x <> ">" } pub fn render_int :: -> String { render 42 } // Never fits any expected type, in every checking position. effect fail { final ctl fail :: reason: String -> Never } // An inferred function that never returns gets a fully polymorphic // result, like Gleam's `panic`: it can stand in for any type. fn boom :: { fail "x" } //~ TYPE boom: fn() -> a / pub fn never_positions :: flag: Bool -> Int / { let a: Int = boom () let xs = [fail "a", 1] let y = if flag { fail "b" } else { 2 } match xs { [] -> fail "c", _ -> a + y } } // ...but not inside a structure. pub fn never_list :: xs: List -> List { xs //~ ERROR E0202 expected `List`, found `List` } // A handler answers for every type an operation's own variables can take // (issue #169): its clauses see them as rigid. effect pick { fn pick :: x: a -> a } fn lie :: -> String / { pick "hello" } pub fn forged :: -> String { handle { lie () } with { pick _ -> 42 //~ ERROR E0202 expected `a`, found `Int` } } pub fn honest :: -> String { handle { lie () } with { pick x -> x } } effect choice { ctl choose :: x: a y: a -> a } pub fn resumed_with_a_fixed_type :: -> Int { handle { choose 1 2 } with { choose _ _ -> resume "one" //~ ERROR E0202 found `String` } } pub fn resumed_with_an_argument :: -> Int { handle { choose 1 2 } with { choose x _ -> resume x } } // The effect's own parameters are fixed by the handled label. effect cell { fn read :: -> s } pub fn read_cell :: -> Int { handle { read () + 1 } with { read -> 41 } }