Lyricdev
GitHub

LYR-SEM0003

an operator its operands do not provide

error · spec 03-types

An operator is applied to a type it is not defined for: arithmetic on a bool or char, < on a type without Ordered, + on a type without the operator interface, same on values that are not references, or a compound assignment through an operator interface on a field or element.

Explanation

The built-in operators work on the numeric types (and + on strings); everything else comes from an interface of std.core — Add, Sub, Neg, … for arithmetic, Ordered for <, <=, >, >=. A type that does not conform has no operator, and operands of two numeric types are not widened to a common one.

Declare the conformance with its method (:: [Add] with fn add(rhs: T): T), convert one operand with as, or call a method instead.

Wrong

fn main(): void {
    let a = true;
    let _ = a + 1;
}
fn main(): void {
    let a = 2;
    let _ = a + 1;
}