E1054: type argument does not meet its constraint

View source

A type parameter may carry a constraint.

A type parameter may carry a constraint. A bound such as T: Reader needs the argument type to have a perform Reader for that type (ADR-0014). The bound Numeric needs an integer or float type. A const parameter such as N: Usize needs a positive compile-time integer or another const parameter (ADR-0072), so 0 is rejected. The message says which parameter, which constraint and which argument. The error points at the type argument that does not meet the constraint.

Example

actus
struct Box[N: Usize] {
    erg item: Int,
}

verb main() {
    erg b: Box[0] = Box[0] { item: 1 };
}
actus
role Reader {
    verb read(abs self: Int) -> Int;
}

verb pull[T: Reader](abs value: T) -> Int {
    return 0;
}

verb main() {
    erg x: u8 = 1u8;
    erg r = pull[u8](value: abs x);
}

Fix

Pass an argument that meets the constraint. Use a positive size for a const parameter. For a role bound, pick a type that has the performance, or write the missing perform.

actus
struct Box[N: Usize] {
    erg item: Int,
}

verb main() {
    erg b: Box[1] = Box[1] { item: 1 };
}
actus
role Reader {
    verb read(abs self: u8) -> Int;
}

perform Reader for u8 {
    verb read(abs self: u8) -> Int {
        return 0;
    }
}

verb pull[T: Reader](abs value: T) -> Int {
    return 0;
}

verb main() {
    erg x: u8 = 1u8;
    erg r = pull[u8](value: abs x);
}

Run actus explain E1054 in your terminal to read this entry offline. Browse Ownership & types or all error codes.