E1122: role method implementation adds an effect

View source

A role method declares the effects that any implementation may have, as an upper bound.

A role method declares the effects that any implementation may have, as an upper bound. A perform block may declare fewer effects, so a pure implementation can satisfy an effect-bearing role. It may not declare an effect that the role does not list, because a call through the role would hide that effect (ADR-0091). The error points at the method in the perform block. The message lists the effects that the role allows and the ones that the implementation declares, written as quoted names or as none.

Example

actus
struct File {
    value: Int,
}

role Writer {
    verb write(abs self: File) -> Int;
}

perform Writer for File {
    meta effect("filesystem")
    verb write(abs self: File) -> Int {
        return self.value;
    }
}

verb main() {
}

Fix

Declare the effect on the role method. Every implementation is then allowed to have it, and the callers of the role see it.

actus
struct File {
    value: Int,
}

role Writer {
    meta effect("filesystem")
    verb write(abs self: File) -> Int;
}

perform Writer for File {
    meta effect("filesystem")
    verb write(abs self: File) -> Int {
        return self.value;
    }
}

verb main() {
}

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