Consider the following:
protocol Foo { typealias A func hello() -> A } protocol FooBar: Foo { func hi() -> A } extension FooBar { func hello() -> A { return hi() } } class FooBarClass: FooBar { typealias A = String func hi() -> String { return "hello world" } }
This code compiles. But if I comment on the explicit definition of the associated type, typealias A = String , then for some reason swiftc will not be able to infer the type.
I believe that this is due to two protocols using the same bound type , but without direct assertion through, for example, type parameterization (maybe the bound type is not powerful / mature enough?), Which makes it ambiguous for type inference.
I'm not sure if this is a language error / immaturity, or maybe I miss some nuances in the protocol extension that rightfully lead to this behavior.
Can someone shed some light on this?
source share