E1116: no performance for a dynamic role

View source

A parameter of type dynamic Role accepts any value whose type performs the role.

A parameter of type dynamic Role accepts any value whose type performs the role. The check happens at the call: the argument's type must have a perform Role for Type block. A type without one cannot be passed, because the compiler has no vtable for it. The role value is a borrowed view, so the parameter is abs (ADR-0017). The message names the role and the type of the argument.

Example

actus
struct File {
    value: Int,
}

struct Other {
    value: Int,
}

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

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

verb send(abs writer: dynamic Writer) -> Int {
    return 0;
}

verb main() {
    erg other = Other { value: 1, };
    send(writer: ref other);
}

Fix

Pass a value of a type that performs the role. You can also add a perform block for the type that you want to pass.

actus
struct File {
    value: Int,
}

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

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

verb send(abs writer: dynamic Writer) -> Int {
    return 0;
}

verb main() {
    erg file = File { value: 1, };
    send(writer: ref file);
}

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