E1050: case mode does not fit the subject

View source

case abs subject inspects a value and leaves it intact, and case dat subject consumes it (ADR-0016).

case abs subject inspects a value and leaves it intact, and case dat subject consumes it (ADR-0016). The subject must be a binding. A dat case moves the subject, so it cannot be an abs binding, which is only a view. case abs needs a binding to freeze, so it cannot take a call result or another expression. The message names the mode and the subject, and says non-binding when the subject is not a name. The error points at the case.

Example

actus
enum Shape {
    Circle(u32),
    Dot,
}

verb name(abs s: Shape) -> Int {
    return case dat s {
        Shape.Circle(r) => 1,
        Shape.Dot => 3,
    };
}

verb main() {
}

Fix

Use case abs to inspect a view. Use case dat only on an owner that the verb may consume, and declare the parameter dat.

actus
enum Shape {
    Circle(u32),
    Dot,
}

verb name(abs s: Shape) -> Int {
    return case abs s {
        Shape.Circle(r) => 1,
        Shape.Dot => 3,
    };
}

verb main() {
}
actus
enum Shape {
    Circle(u32),
    Dot,
}

verb name(dat s: Shape) -> Int {
    return case dat s {
        Shape.Circle(r) => 1,
        Shape.Dot => 3,
    };
}

verb main() {
}

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