Bugzilla – Bug 322010
[GMCS] does not compile arithmetic operations requiring lifted conversion
Last modified: 2013-11-24 08:59:50 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".
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; } }
Reassigning to Miguel to drive further resolution...
Fixed