Bugzilla – Bug 323006
[PATCH] More implicit casts not considered with compound assignments
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by martin.voelkle@gmail.com 2006-12-19 09:45:40 MST ---- Description of Problem: Weird case not fixed by https://bugzilla.novell.com/show_bug.cgi?id=MONO80313: using System; namespace Bugs { class https://bugzilla.novell.com/show_bug.cgi?id=MONO2 { struct MyByte { private byte value; public MyByte(byte value) { this.value = value; } public static implicit operator MyByte(byte value) { return new MyByte(value); } public static implicit operator byte(MyByte b) { return b.value; } } public static void Main(string[] args) { MyByte b = 255; b += 255; Console.WriteLine(b); } } } Assignment "b += 255" fails although 255 is implicitely convertible to MyByte. https://bugzilla.novell.com/show_bug.cgi?id=MONO2.cs(27,13): error CS0031: Constant value `int' cannot be converted to a `Bugs.https://bugzilla.novell.com/show_bug.cgi?id=MONO2.MyByte' ---- Additional Comments From martin.voelkle@gmail.com 2006-12-19 12:27:54 MST ---- Created an attachment (id=171141) Fix to apply to mcs/mcs/assign.cs. Lacks the check that the selected operator is a predefined operator ---- Additional Comments From miguel@ximian.com 2007-01-01 04:18:46 MST ---- CCing Marek for his opinion. ---- Additional Comments From marek.safar@seznam.cz 2007-02-09 19:21:55 MST ---- Sorry for the delay, the patch was applied. Thanks for the effort. Imported an attachment (id=171141) Unknown operating system unknown. Setting to default OS "Other".