Bug 18866

Summary: Mono C# compiler incorrectly emits CS0221 compiler error when casting the bitwise compliment of a ushort typed enum to a ushort variable
Product: [Mono] Compilers Reporter: emoriarty
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono, sig-rnd-sat-mono-bugs
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Tags: Is this bug a regression?: ---
Last known good build:

Description emoriarty 2014-04-08 14:24:28 UTC
The mono C# compiler incorrectly emits CS0221 when casting the bitwise compliment of a ushort enum into a ushort variable. 

===== Test.cs =====
     1  class Test {
     2      public enum E : ushort
     3      {
     4          Mask = 0
     5      }
     6      public ushort foo()
     7      {      
     8          ushort Mask = (ushort)(~E.Mask);
     9          return Mask;
    10      }
    11  }
===== End of Test.cs =====

Command Lines:

From Visual Studio 2013 Command Prompt
$ csc /target:library Test.cs
Microsoft (R) Visual C# Compiler version 12.0.21005.1
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

From Mono-3.4.0 command prompt
$ mcs /target:library Test.cs
Test.cs(8,35): error CS0221: Constant value `-1' cannot be converted to a `ushort' (use `unchecked' syntax to override)
Compilation failed: 1 error(s), 0 warnings

Other Mono Versions:
2.11.4.0: fail
3.0.0.0: fail
3.0.7.0: fail
3.1.1.0: fail
3.2.6.0: fail
3.4.0.0: fail

Edward Moriarty | Junior Engineer
Coverity | The Leader in Development Testing
Comment 1 Marek Safar 2014-05-05 08:58:08 UTC
Fixed in master