E1147: `abs` view of a scalar type

View source

A scalar has no view.

A scalar has no view. An abs struct field is laid out as a pointer to its source (ADR-0046 2.3), but a scalar abs parameter is passed by value, so a holder built from such a parameter would carry a pointer into the dead frame of the callee. Reading the field also fails LLVM verification. The declaration is therefore rejected when the field type is Int, Bool, Usize, a fixed-width integer (u8 to i64) or a float. String, Buffer, structs, enums, packs and arrays can be viewed and stay allowed. The message names the field, the struct and the type. The error points at the field.

The same rule applies to a type argument written abs <scalar>, such as Option[abs Int], Result[abs u8, E], Box[abs Int] or Array[abs Int, 2]: the payload is a pointer, but a scalar abs is passed by value (ADR-0126). The error points at the argument. An enum payload written abs <scalar>, such as V(abs Int), is rejected the same way. It is also reported at the instantiation Box[Int] when Box holds abs T, naming the parameter and the scalar.

Example

actus
struct Count {
    abs held: Int,
}

verb main() {
}
actus
verb keep(abs number: Int) -> Option[abs Int] {
    return Option[abs Int].Some(number);
}

verb main() {
}

Fix

Declare a plain field, which copies the value.

actus
struct Count {
    held: Int,
}

verb main() {
}

Run actus explain E1147 in your terminal to read this entry offline. Browse Modules & rules or all error codes.