Bug 324996 (MONO82327) - [GMCS] CS0184 always reported using is operator on nullable
Summary: [GMCS] CS0184 always reported using is operator on nullable
Status: RESOLVED FIXED
Alias: MONO82327
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.2
Hardware: Other All
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Marek Safar
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-05 19:06 UTC by Gert Driesen
Modified: 2007-11-12 19:14 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:47:05 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

Comment 2 Marek Safar 2007-11-09 16:15:05 UTC
Fixed in SVN.

Note: we now report correctly CS0183 warning which csc as in many other cases does not.
Comment 3 Gert Driesen 2007-11-09 22:55:07 UTC
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.
Comment 4 Marek Safar 2007-11-12 19:14:20 UTC
Fixed in SVN.

If you are aware of any other special cases, please let me know.