This is my code:
protocol Person {
associatedtype Homework
static func generate(homeWork: Homework) -> Self
}
extension Person {
static func generate(homeWork: Homework) -> Self {
fatalError()
}
}
// Method 'generate(homeWork:)' in non-final class 'Teacher'
// cannot be implemented in a protocol extension because it
// returns 'Self' and has associated type requirements
class Teacher: Person {
typealias Homework = Int
}
Despite the strange naming of types, I am curious why it isn't possible to conform a non-final class to a protocol which has a method that returns Self and having a associatedtype as parameter type.
Note: I am not asking how to fix this problem (because I can just mark my class final). I want to know why this isn't possible.
I think it is strange. Protocols with associatedtypes and Self is always a struggle ofcourse, but when using one of two (returning Self/associatedtype protocol type in parameter) compiles the code just fine.
Why can't I conform to a protocol which has a default implementation of a method whereas the method has a return type of Self and associatedtype in a parameter, but when only using one of them the code compiles? Why is both a problem when dealing with inherence (because marking the class as final fixes the error message, so it has to be something with inherence)?