title: Failing cast in Swift from Any? to protocol
body: <p>FYI: Swift bug raised here: <a href="https://bugs.swift.org/browse/SR-3871" rel="noreferrer">https://bugs.swift.org/browse/SR-3871</a></p>
  
  <hr>
  
  <p>I'm having an odd problem where a cast isn't working, but the console shows it as the correct type.</p>
  
  <p>I have a public protocol</p>
  
  <pre><code>public protocol MyProtocol { }
  </code></pre>
  
  <p>And I implement this in a module, with a public method which return an instance.</p>
  
  <pre><code>internal struct MyStruct: MyProtocol { }
  
  public func make() -&gt; MyProtocol { return MyStruct() }
  </code></pre>
  
  <p>Then, in my view controller, I trigger a segue with that object as the sender</p>
  
  <pre><code>let myStruct = make()
  self.performSegue(withIdentifier: "Bob", sender: myStruct)
  </code></pre>
  
  <p>All good so far.</p>
  
  <p>The problem is in my <code>prepare(for:sender:)</code> method.</p>
  
  <pre><code>override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if segue.identifier == "Bob" {
          if let instance = sender as? MyProtocol {
              print("Yay")
          }
      }
  }
  </code></pre>
  
  <p>However, the cast of instance to MyProtocol always returns <code>nil</code>.</p>
  
  <p>When I run <code>po sender as! MyProtocol</code> in the console, it gives me the error <code>Could not cast value of type '_SwiftValue' (0x1107c4c70) to 'MyProtocol' (0x1107c51c8)</code>. However, <code>po sender</code> will output a valid <code>Module.MyStruct</code> instance.</p>
  
  <p>Why doesn't this cast work?</p>
  
  <p>(I've managed to solve it by boxing my protocol in a struct, but I'd like to know why it's not working as is, and if there is a better way to fix it)</p>