[Mono-bugs] [Bug 73394][Min] New - mcs crashes when an instance data member with the name as a a type is referenced under static context

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sat, 5 Mar 2005 23:29: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 t.manki@gmail.com.

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

--- shadow/73394	2005-03-05 23:29:47.000000000 -0500
+++ shadow/73394.tmp.31702	2005-03-05 23:29:47.000000000 -0500
@@ -0,0 +1,71 @@
+Bug#: 73394
+Product: Mono: Compilers
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Minor
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: t.manki@gmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: mcs crashes when an instance data member with the name as a a type is referenced under static context
+
+Description of Problem:
+When a class has a data member that has the same name as an existing class,
+referencing that member under static context (inside a static method)
+results in an uncaught exception during compilation.
+
+class's name
+
+
+Steps to reproduce the problem:
+Compile this code:
+
+using System;
+
+public class MemRefMonoBug {
+	private string String;	// this member has the same name as System.String class
+	public static void Main ()
+	{
+		new MemRefMonoBug ().String = "";	// this line causes no problem
+		String = "";	// mcs crashes in this line
+	}
+}
+
+Actual Results:
+Exception caught by the compiler while compiling:
+   Block that caused the problem begin at: MemRefMonoBug.cs: (20)
+                     Block being compiled: [MemRefMonoBug.cs:
+(21),MemRefMonoBug.cs: (24)]
+System.NullReferenceException: Object reference not set to an instance of
+an object
+        in FieldExpr.EmitInstance (Mono.CSharp.EmitContext)
+        in FieldExpr.EmitAssign (Mono.CSharp.EmitContext,
+Mono.CSharp.Expression, System.Boolean, System.Boolean)
+        in Assign.Emit (Mono.CSharp.EmitContext, System.Boolean)
+        in Assign.EmitStatement (Mono.CSharp.EmitContext)
+        in StatementExpression.DoEmit (Mono.CSharp.EmitContext)
+        in Statement.Emit (Mono.CSharp.EmitContext)
+        in Block.DoEmit (Mono.CSharp.EmitContext)
+        in Block.Emit (Mono.CSharp.EmitContext)
+        in EmitContext.EmitTopBlock (Mono.CSharp.Block,
+Mono.CSharp.InternalParameters, Mono.CSharp.Location)
+
+Expected Results:
+(Taken from MS compiler)
+
+MemRefMonoBug.cs(41,3): error CS0120: An object reference is required for the
+        nonstatic field, method, or property 'MemRefMonoBug.String'
+
+How often does this happen? 
+Always
+
+Additional Information:
+mcs handles well the situation if the data member's name is not an existing
+class's name