[Mono-bugs] [Bug 38935][Nor] New - mcs allows derived class constructors to write to readonly fields of a base class

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Fri, 28 Feb 2003 23:56:47 -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 mathpup@mylinuxisp.com.

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

--- shadow/38935	Fri Feb 28 23:56:47 2003
+++ shadow/38935.tmp.29457	Fri Feb 28 23:56:47 2003
@@ -0,0 +1,62 @@
+Bug#: 38935
+Product: Mono/MCS
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: mathpup@mylinuxisp.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: mcs allows derived class constructors to write to readonly fields of a base class
+
+Description of Problem: 
+ 
+When a class declared a "readonly" field, only constructors of that class should be 
+able to write to that field. However, mcs permits a derived-class constructor to write 
+to that field, which is incorrect (ECMA 17.4.2). 
+ 
+ 
+Steps to reproduce the problem: 
+1. Compile program below: mcs readonly.cs 
+ 
+Actual Results: 
+ 
+``Compilation succeeded'' 
+ 
+ 
+Expected Results: 
+ 
+readonly.cs(11,3): error CS0191:         A readonly field cannot be assigned to 
+(except in a constructor or a variable initializer) 
+ 
+ 
+How often does this happen?  
+ 
+Always 
+ 
+Additional Information: 
+ 
+//Compile: mcs readonly.cs 
+public class Base 
+{ 
+	public readonly int x; 
+} 
+ 
+ 
+public class Derived: Base 
+{ 
+	public Derived() 
+	{ 
+		x = 0; 
+	} 
+ 
+ 
+	public static void Main() {} 
+}