title: Why isn't the C# compiler able to cast a literal negative value to an enum?
body: <p>This code does not compile with the <a href="http://tryroslyn.azurewebsites.net/#b:master/f:&gt;il/K4Zwlgdg5gBAygTxAFwKYFsDcAoADsAIwBswBjGUogQxBBgGEYBvbGNmfYsmANwHswAExgBZABQBKZq3ayAkhGQBRCMHQB+GFRgBeGGIXLV6CQFoAjDlkBfbLbyES5VMZiGVamAC4YkZM2sgA===" rel="noreferrer">latest C# compiler</a>:</p>
  
  <pre><code>public class Program
  {
      public static void Main()
      {
          IntEnum a = (IntEnum)-1;
      }
  }
  
  public enum IntEnum : int { }
  </code></pre>
  
  <p>When you attempt to compile it, it raises</p>
  
  <blockquote>
    <p>(3,22,3,29): Error CS0119: 'IntEnum' is a type, which is not valid in the given context</p>
  </blockquote>
  
  <p>Strangely, changing the casted value to a positive number (such as <code>4</code>), or using a const value (such as <code>int.MinValue</code>), or even surrounding the value with parentheses like <code>(IntEnum)(-1)</code> will compile and work just fine. However, the above sample does not.</p>
  
  <p>Is there any reason for this? Is it possible that Roslyn is perhaps parsing the code incorrectly, and that's why an error is getting raised?</p>