package foo:foo; interface types-interface { /// "package of named fields" record r { a: u32, b: string, c: list>> } /// values of this type will be one of the specified cases variant human { baby, /// type payload child(u32), // optional type payload adult, } /// similar to `variant`, but no type payloads enum errno { too-big, too-small, too-fast, too-slow, } /// a bitflags type flags permissions { read, write, exec, } // type aliases are allowed to primitive types and additionally here are some // examples of other types type t1 = u32; type t2 = tuple; type t3 = string; type t4 = option; /// no "ok" type type t5 = result<_, errno>; // no "ok" type type t6 = result; // no "err" type type t7 = result; // both types specified type t8 = result; // no "ok" or "err" type type t9 = list; type t10 = t9; } /// Comment for import interface interface api-imports { use types-interface.{t7}; /// Same name as the type in `types-interface`, but this is a different type variant human { baby, child(u64), adult(tuple>, tuple>), } api-a1-b2: func(arg: list) -> (h1: t7, val2: human); } interface api { /// Comment for export function f1: func() -> (val-one: tuple, val2: string); /// Comment for t5 in api type t5 = result<_, option>; record errno { a-u1: u64, /// A list of signed 64-bit integers list-s1: list, str: option, c: option, } class: func(break: option>) -> tuple; continue: func(abstract: option>, extends: tuple) -> (%implements: option>); } world types-example { use types-interface.{t2 as t2-renamed, t10, permissions}; import api-imports; import print: func(message: string, level: log-level); /// Comment for import inline import inline: interface { /// Comment for import inline function inline-imp: func(args: list>) -> result<_, char>; } export types-interface; export api; enum log-level { /// lowest level debug, info, warn, error, } // NB: this record used to be empty, but that's no longer valid, so now it's // non-empty. Don't want to delete the whole test however. record empty { not-empty-anymore: bool, } export f-f1: func(typedef: t10) -> t10; export f1: func(f: f32, f-list: list>) -> (val-p1: s64, val2: string); /// t2 has been renamed with `use self.types-interface.{t2 as t2-renamed}` export re-named: func(perm: option, e: option) -> t2-renamed; export re-named2: func(tup: tuple>, e: empty) -> tuple, s8>; }