title: Expression of type T cannot be handled by a pattern of type X
body: <p>I have upgraded my project to target C# 7 and used Visual Studio 2017 RC to implement pattern matching across my solution. After doing this some errors were introduced relating to pattern matching with generic parameters.</p>
  
  <p>Consider the following code:</p>
  
  <pre><code>public class Packet
  {
  }
  
  public class KeepalivePacket : Packet
  {
  }
  
  public void Send&lt;T&gt;(T packet)
      where T : Packet
  {
      if (packet is KeepalivePacket keepalive)
      {
          // Do stuff with keepalive
      }
  
      switch (packet)
      {
          case KeepalivePacket keepalivePacket:
              // Do stuff with keepalivePacket
              break;
      }
  }
  </code></pre>
  
  <p>Both the <code>if</code> statement and the <code>case</code> statement produce a compilation error.</p>
  
  <blockquote>
    <p>An expression of type T cannot be handled by a pattern of type KeepalivePacket</p>
  </blockquote>
  
  <p>If I first cast the parameter to type <code>object</code> the pattern matching works as expected. Roslyn then marks the cast to <code>object</code> as redundant.</p>
  
  <pre><code>if ((object)packet is KeepalivePacket keepalive)
  {
      // This works
  }
  </code></pre>
  
  <p>This error only appears to apply to generic parameters and variables. Roslyn appears to not be aware of this issue as it recommends changing the code to use pattern matching via an analyzer and allows me to apply the "code fix" resulting in the broken code.</p>