Protocol reported as having 'Self or associated type requirements', when it doesn't have any

微笑、不失礼 提交于 2020-01-06 03:30:47

问题


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:

Where is the associated type supposed to come from?
(Even if I remove the "\(Self.self)" it still complains.)


回答1:


Equatable has Self as an associated type requirement and LanguageType is indirectly derived from Equatable, therefore LanguageType has Self as an associated type requirement.



来源:https://stackoverflow.com/questions/34693732/protocol-reported-as-having-self-or-associated-type-requirements-when-it-does

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!