Avatar
omochimetaru 3/8/2019 7:08 AM
struct IntError : Error { var value: Int } func mutateError(_ e: inout Error) {} struct Cat { var error: IntError } func main() { var cat = Cat(error: IntError(value: 3)) // Cannot pass immutable value as inout argument: implicit conversion from 'IntError' to 'Error' requires a temporary mutateError(&cat.error) }
7:12 AM
existentialへの変換はアップキャストみたいな扱いで、戻してくるところはダウンキャストみたいに非安全としてガードされる
7:16 AM
import Foundation @objc protocol P { } func genericP<T: P>(_ t: T) {} func existentialP(_ p: P) { genericP(p) }
7:16 AM
Yes, there’s already logic to detect and diagnose this case in fact (@objc protocols are self-conforming, except when they contain static members or initializers).
7:16 AM
Yes, there’s already logic to detect and diagnose this case in fact (@objc protocols are self-conforming, except when they contain static members or initializers). Slava ···On Jan 18, 2017, at 12:10 AM, Anton Zhilin via swift-evolution wrote: There is also a caveat w...
7:16 AM
@objc protocol は self-conformance していて、その条件チェックもされてるって!
7:17 AM
import Foundation @objc protocol P { init() } func genericP<T: P>(_ t: T) {} func existentialP(_ p: P) { // Cannot invoke 'genericP' with an argument list of type '(P)' genericP(p) } pにinitつけたらエラーになった。