E1057: duplicate method in a role

View source

A role names each of its methods once, and a perform block gives each method one body (ADR-0014).

A role names each of its methods once, and a perform block gives each method one body (ADR-0014). A second method with the same name is rejected, whether it is declared in the role or defined in the perform. The message names the method and the role. The error points at the second method.

Example

actus
struct Cursor {
    position: Int,
}

role Reader {
    verb read(abs self: Cursor) -> Int;
    verb read(abs self: Cursor) -> Int;
}

verb main() {
}
actus
struct Cursor {
    position: Int,
}

role Reader {
    verb read(abs self: Cursor) -> Int;
}

perform Reader for Cursor {
    verb read(abs self: Cursor) -> Int {
        return 0;
    }

    verb read(abs self: Cursor) -> Int {
        return 1;
    }
}

verb main() {
}

Fix

Keep one method of each name. Give a second method a name of its own if both are needed.

actus
struct Cursor {
    position: Int,
}

role Reader {
    verb read(abs self: Cursor) -> Int;
    verb peek(abs self: Cursor) -> Int;
}

verb main() {
}
actus
struct Cursor {
    position: Int,
}

role Reader {
    verb read(abs self: Cursor) -> Int;
}

perform Reader for Cursor {
    verb read(abs self: Cursor) -> Int {
        return 0;
    }
}

verb main() {
}

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