Avatar
protocol P { associatedtype T func f(_ g: @escaping (T) -> Void) } class C<S>: P { typealias T = S private let _f: ((S) -> Void) -> Void init<Q: P>(q: Q) where Q.T == T { // Error: cannot assign value of type '((S) -> Void) -> Void' to type '((S) -> Void) -> Void' self._f = { g -> Void in q.f(g) } } func f(_ g: @escaping (S) -> Void) { self._f(g) } } でエラーメッセージが不親切な件の原因を探している過程で、意図のわからないコードがあったので質問させてください // Try to simplify irrelevant details of function types. For example, if // someone passes a "() -> Float" function to a "() throws -> Int" // parameter, then uttering the "throws" may confuse them into thinking that // that is the problem, even though there is a clear subtype relation. if (auto srcFT = exprType->getAs<FunctionType>()) if (auto destFT = contextualType->getAs<FunctionType>()) { auto destExtInfo = destFT->getExtInfo(); if (!srcFT->isNoEscape()) destExtInfo = destExtInfo.withNoEscape(false); // 👈 ですが、これコメントの通り関数の型の不一致に escaping とか throws とか混ぜるとややこしいので出さない的な意図であってそうでしょうか? https://github.com/apple/swift/blob/5e7da0e3dcf13c603233c1f2aad1f1aded8821df/lib/Sema/CSDiag.cpp#L3250
swift - The Swift Programming Language
11:38 AM
あれ、ちょっと思ってたのと違うな… この分岐で拾われているように見える
11:45 AM
コードリーディングだけだとちょっとつらいですね…これ実際に swiftc を debug build して見ないとすぐにはわからなさそう…