Hi Slava, Thanks for your quick response!
I see. That's in line with what I can read from the Type Constraint Syntax section in the official Swift book. Satoshi On Tue, May 2, 2017 at 1:59 AM, Slava Pestov <spes...@apple.com> wrote: > Hi Satoshi, > > Protocols do not conform to themselves. Only concrete types can conform to > protocols in the current implementation of Swift. > > Slava > > > On May 2, 2017, at 1:57 AM, Satoshi Nakagawa via swift-users < > swift-users@swift.org> wrote: > > > > Hi, > > > > I got a build error "Generic parameter 'T' could not be inferred" for > the following code. > > > > Can anyone explain why we can't use a protocol to infer the generic type > T? > > > > class Emitter { > > func emit<T: Emittable>() -> T { > > ... > > } > > } > > > > protocol Emittable {} > > protocol Subemittable: Emitable {} > > > > class ConcreteEmittable: Subemittable {} > > > > func testCode() { > > let emitter = Emitter() > > > > // Error: Generic parameter 'T' could not be inferred > > let _: Emittable = emitter.emit() > > > > // Error: Generic parameter 'T' could not be inferred > > let _: Subemittable = emitter.emit() > > > > // This works > > let _: ConcreteEmittable = emitter.emit() > > } > > > > Thanks, > > Satoshi > > > > _______________________________________________ > > swift-users mailing list > > swift-users@swift.org > > https://lists.swift.org/mailman/listinfo/swift-users > >
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users