[swift-users] Instantiating a generic class with a protocol type

Matthias Zenger matthias at objecthub.net
Mon Apr 11 11:33:59 CDT 2016

Hi everyone,

I'm puzzled by the following behaviour in Swift 2.2. This code compiles and
behaves as expected:

  protocol Executable {}
  class Box<T: Any> {}
  let box = Box<Executable>()

If I now replace the type constraint on T with Executable, I'm getting a
compiler error:

  protocol Executable {}
  class Box<T: *Executable*> {}
  let box = Box<Executable>()

>From a type-theoretic perspective, I can't see why instantiating class Box
with type Executable should be prohibited. Also the corresponding error
message isn't really providing more insights: "Using 'Executable' as a
concrete type conforming to protocol 'Executable' is not supported".

Where can I find more about this behaviour in the Swift Language
Specification? Is this a known bug?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160411/04b8ea13/attachment.html>

More information about the swift-users mailing list