Bug 322010 (MONO79301) - [GMCS] does not compile arithmetic operations requiring lifted conversion
Summary: [GMCS] does not compile arithmetic operations requiring lifted conversion
Status: RESOLVED FIXED
Alias: MONO79301
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Marek Safar
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-06 18:54 UTC by Marek Safar
Modified: 2013-11-24 08:59 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:08:59 UTC


---- Reported by marek.safar@seznam.cz 2006-09-06 11:54:11 MST ----

Please fill in this template when reporting a bug, unless you know what you
are doing.
Description of Problem:


Steps to reproduce the problem:
1. 

class T
{
	public void Foo ()
	{
		int? f = null * null + null / null % null;
	}
}

Actual Results:

error CS0037: Cannot convert null to `int' because it is a value type


Expected Results:

No error.

How often does this happen? 


Additional Information:



---- Additional Comments From rharinath@novell.com 2006-09-08 04:02:20 MST ----

Hmm.  I'm puzzled how this can work.  'null' can be lifted to _any_
nullable type, so why is this not ambiguous?  What's special about
Nullable<int>?




---- Additional Comments From marek.safar@seznam.cz 2006-09-24 07:40:45 MST ----

It seems to me, that during constant folding null -> int conversion is
allowed.

When I tried

byte? i = null / null;

I got 

error CS0266: Cannot implicitly convert type 'int?' to 'byte?'. An
explicit conversion exists (are you missing a cast?)


Unknown operating system unknown. Setting to default OS "Other".

Comment 1 Marek Safar 2008-07-22 17:51:07 UTC
6.1.5 explains why it is allowed but some results are still unexpected

using System;

class Program
{
	static int Main ()
	{
		int? i1 = null + null; // CS0034: Operator '+' is ambiguous
		int? i2 = null * null; // OK
		int? i3 = null / null; // OK
		int? i5 = null % null; // OK
		int? i6 = null - null; // OK
		int? i7 = null ^ null; // CS0034: Operator '^' is ambiguous
		int? i8 = null & null; // CS0034: Operator '&' is ambiguous
		int? i9 = null >> 1; // OK
		
		bool? b = null > null; // OK
		bool? b2 = null < null; // OK
		
		return 0;
	}
}

Comment 3 Susanne Oberhauser-Hirschoff 2011-07-20 12:29:54 UTC
Reassigning to Miguel to drive further resolution...
Comment 4 Marek Safar 2013-11-24 08:59:50 UTC
Fixed