A protocol is reported as having "I or related type requirements" when it does not have

I have the following code:

protocol LanguageType: Hashable {
    var description: String { get }
}

extension LanguageType {
    var description: String { return "(Self.self)" }
    var hashValue: Int { return "(Self.self)".hashValue }
}

func ==<T: LanguageType, U: LanguageType>(left: T, right: U) -> Bool {
    return left.hashValue == right.hashValue
}

struct English: LanguageType { }

When I do the following:

let english: LanguageType = English()

I get the following error:

Mistake

Where should the associated type come from? (Even if I delete "\(Self.self)", he still complains.)

+1
source share
1 answer

EquatableIt has a Selftype requirement as a requirement, but is LanguageTypeindirectly derived from Equatable, therefore it LanguageTypehas a Selftype type requirement.

+2
source

Source: https://habr.com/ru/post/1623539/


All Articles