[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
Fri, 26 Mar 2004 00:00:44 -0500 (EST)
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 bmaurer@users.sf.net.
http://bugzilla.ximian.com/show_bug.cgi?id=49488
--- shadow/49488 2004-03-26 00:00:44.000000000 -0500
+++ shadow/49488.tmp.21217 2004-03-26 00:00:44.000000000 -0500
@@ -0,0 +1,54 @@
+Bug#: 49488
+Product: Mono: Compilers
+Version: unspecified
+OS: unknown
+OS Details:
+Status: NEW
+Resolution:
+Severity: Unknown
+Priority: Wishlist
+Component: C#
+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.
+
+------- Additional Comments From bmaurer@users.sf.net 2004-03-26 00:00 -------
+If we accept this construct, we generate invalid IL code, and the code
+may not work right (the runtime is free to resolve a member of a
+readonly struct at jit time). So, I think an error is correct here.