Bugzilla – Bug 324248
[GMCS] implicite conversion to boolean from generic using == does not work
Last modified: 2008-03-04 09:47:53 UTC
---- Reported by wasabi@larvalstage.net 2007-05-08 17:37:01 MST ---- I have been assured the following code compiles correctly on MS.Net. However, I don't have a box at the time to verify it. It doesn't compile on Mono 1.2.3... and it appears it should. using System; namespace MonoBug { class MainClass { public static void Main(string[] args) { Console.WriteLine("Hello World!"); GenericType<bool> g = new GenericType<bool>(true); if (g) Console.WriteLine("true"); if (g == true) Console.WriteLine("true"); } } public class GenericType<T> { private T value; public GenericType(T value) { this.value = value; } public static implicit operator T(GenericType<T> o) { return o.value; } } } Unknown operating system unknown. Setting to default OS "Other".
Just to confirm (for Windows) and to show the error that gmcs reports... C:\temp>csc 324248.cs Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42 for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727 Copyright (C) Microsoft Corporation 2001-2005. All rights reserved. C:\temp>324248 Hello World! true true gmcs 324248.cs 324248.cs(11,29): error CS0019: Operator `==' cannot be applied to operands of type `MonoBug.GenericType<bool>' and `bool' Compilation failed: 1 error(s), 0 warnings
Fixed in SVN.