Bug 323269 (MONO80581) - [GMCS] Unable to compare a struct to null
Summary: [GMCS] Unable to compare a struct to null
Status: RESOLVED WONTFIX
Alias: MONO80581
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.2
Hardware: Other Linux
: P3 - Medium : Minor
Target Milestone: ---
Assignee: Raja R Harinath
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-22 19:41 UTC by Pawel Sakowski
Modified: 2007-09-15 21:24 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:23:50 UTC


---- Reported by pawel.sakowski@mindbreeze.com 2007-01-22 12:41:31 MST ----

Description of Problem:
gmcs is unable to compare value types to null.

Steps to reproduce the problem:
1. Attempt to compile the following code:

class X{static void Main(){
if (System.DateTime.Now == null);
}}

Actual Results:
struct-vs-null.cs(2,1): warning CS0642: Possible mistaken empty statement
struct-vs-null.cs(2,21): error CS0019: Operator `==' cannot be applied to
operands of type `System.DateTime' and `null'
Compilation failed: 1 error(s), 1 warnings

Expected Results:
A successful compilation (the warning is O.K.)

How often does this happen?
100%

Additional Information:
csc compiles the same code successfully.
mono 1.2

How pointless such a comparison is is beyond the scope of this report.



---- Additional Comments From gert.driesen@pandora.be 2007-01-22 17:26:32 MST ----

Note: csc 1.x reports the same error, but using csc 2.x it compiles 
fine.



---- Additional Comments From miguel@ximian.com 2007-01-28 13:33:49 MST ----

I can not find a place in the spec that addresses this issue (the
closest I found was related to nullable types).

I do not want to support this without a good reason, because the code
above is masking a real problem: that comparing "Now" to null is
always going to be false (always, not sometimes, but always).





---- Additional Comments From pawel.sakowski@mindbreeze.com 2007-01-29 05:13:35 MST ----

Yes, looks like the spec is pretty silent about this. It seems that
neither the results of such a comparison are specified, nor is it
explicitly forbidden.

Regarding "always going to be false": yes, that's exactly what I meant
with "pointless". The pre-existing code I've met that triggered this
issue used a comparison of a struct to null as an over-eager check for
ArgumentNullException.