Very confused about some compiler warnings related to protocols—bugs or intended?

What you are looking for is "opening existential type". This was discussed in Improving the UI of generics, but not yet implemented.

With the hypothetical syntax from the the discussion it would look like this:

func process() {
   let <X: FooProtocol> openedFoo = someSpecificFoo 
   let bar = Bar<X>(foo: openedFoo)
}

Current workaround for that is to move code depending on the opened type to the protocol extension, like you did with instancePerform().

1 Like