Bugzilla – Bug 324996
[GMCS] CS0184 always reported using is operator on nullable
Last modified: 2007-11-12 19:14:20 UTC
---- Reported by gert.driesen@pandora.be 2007-08-05 12:06:06 MST ---- gmcs currently incorrectly reports error CS0184 for the following code: class Program { static int Main () { int? num1 = null; if (num1 is int) return 1; int? num2 = 5; if (!(num2 is int)) return 2; return 0; } } Expected result: Successful compilation Actual result: test.cs(6,26): error CS0184: The given expression is never of the provided (`int') type test.cs(10,28): error CS0184: The given expression is never of the provided (`int') type
Fixed in SVN. Note: we now report correctly CS0183 warning which csc as in many other cases does not.
Marek, you're wrong about this. A nullable int is of course not always an int. Try compiling and running the following code: using System; class Program { static void Main () { int? i = null; if (i is int) { Console.WriteLine ((int) i + 3); } } } When compiled with gmcs, this results in an InvalidOperationException (Nullable object must have a value), while it should not.
Fixed in SVN. If you are aware of any other special cases, please let me know.