[Mono-bugs] [Bug 49488][Wis] New - Wish for compiler warning about readonly modifier on struct type field

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 9 Oct 2003 10:06:02 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by sestoft@dina.kvl.dk.

http://bugzilla.ximian.com/show_bug.cgi?id=49488

--- shadow/49488	2003-10-09 10:06:02.000000000 -0400
+++ shadow/49488.tmp.1704	2003-10-09 10:06:02.000000000 -0400
@@ -0,0 +1,49 @@
+Bug#: 49488
+Product: Mono/MCS
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: sestoft@dina.kvl.dk               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Wish for compiler warning about readonly modifier on struct type field
+
+Description of Problem:
+
+When a field s of struct type is declared readonly, assignments to fields
+of s will no longer have any effect.  It would be good too issue a warning
+because this may not be what the programmer expects.
+
+Consider this program:
+
+using System;
+
+struct S {
+  public int x;
+}
+
+class C {
+  static readonly S s;
+
+  public static void Main(String[] args) {
+    s.x = 42;
+    Console.WriteLine(s.x);
+  }
+}
+
+Mono 0.26 compiles this program without any complaints, but the program
+prints 0.  This is actually according to the C# specification, but it would
+be desirable to issue a warning that the assignment s.x = 42 has absolutely
+no effect. 
+
+Microsoft csc 1.1 and 1.2 alpha flag the assignment as an error, which is
+another possibility, although it is unclear whether this is actually
+supported by the specification.