[Mono-bugs] [Bug 52458][Nor] New - Scope problem when overriding private method in nested type

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sat, 7 Feb 2004 12:49: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 miguel@ximian.com.

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

--- shadow/52458	2004-02-07 12:49:44.000000000 -0500
+++ shadow/52458.tmp.21743	2004-02-07 12:49:44.000000000 -0500
@@ -0,0 +1,115 @@
+Bug#: 52458
+Product: Mono/Compilers
+Version: unspecified
+OS: unknown
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: Unknown
+Priority: Normal
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: bmaurer@users.sf.net               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Scope problem when overriding private method in nested type
+
+This should not compile:
+
+using System;
+
+class A {
+	public virtual int Blah () { return 1; }
+}
+
+class B : A {
+	new int Blah () { return 0; }
+	
+	class C : B {
+		
+		public override int Blah () { return 2; }
+		static void Main () {
+			Console.WriteLine (new C ().Blah ());
+		}
+	}
+}
+
+B.Blah is closer to C.Blah than A.Blah is. We are ignoring it because we
+just ignore the private methods.
+
+On csc you get:
+
+t.cs(14,23): error CS0506: 'B.C.Blah()' : cannot override inherited member
+'B.Blah()' because it is not marked virtual, abstract, or override
+t.cs(10,10): (Location of symbol related to previous error)
+t.cs(14,23): error CS0507: 'B.C.Blah()': cannot change access modifiers
+when overriding 'private' inherited member 'B.Blah()'t.cs(10,10): (Location
+of symbol related to previous error)
+
+------- Additional Comments From bmaurer@users.sf.net  2003-12-22 16:07 -------
+Related:
+
+We compile
+
+using System;
+ 
+class A {
+        public virtual int Blah () { return 1; }
+}
+ 
+class B : A {
+        new public static int Blah () { return 0; }
+ 
+        class C : B {
+ 
+                public override int Blah () { return 2; }
+                static void Main () {
+                        Console.WriteLine (new C ().Blah ());
+                }
+        }
+}
+
+csc gives
+
+t.cs(12) error CS0506: `B.C.Blah': cannot override inherited member
+`B.Blah' because it is not virtual, abstract or override
+
+
+------- Additional Comments From bmaurer@users.sf.net  2003-12-22 17:04 -------
+wrt to the origional issue, it looks like csc is not respecting the spec:
+"For the purposes of locating the overridden base method, a method is
+considered accessible if it is public, if it is protected, if it is
+protected internal, or if it is internal and declared in the same
+program as C."
+
+This says nothing about private and nested types. However, this
+statement is a departure from the normal accessibility rules, so we
+should go with csc, I think.
+
+On the other one, it is crystal clear:
+
+"The overridden base method is a virtual, abstract, or override
+method. In other words, the overridden base method cannot be static or
+non-virtual."
+
+wrt the second problem, the spec is quite clear:
+
+
+
+------- Additional Comments From bmaurer@users.sf.net  2003-12-23 00:45 -------
+Created an attachment (id=6297)
+Patchedy patch patch
+
+
+------- Additional Comments From bmaurer@users.sf.net  2003-12-23 00:47 -------
+This patch should clear up these two issues at least, they make the
+scoping stuff alot cleaner.
+
+Also gives a pretty nice perf boost. I get .5 s improvement on corlib.
+
+------- Additional Comments From bmaurer@users.sf.net  2003-12-23 12:28 -------
+Created an attachment (id=6303)
+Ignore the last version of this patch it is fscked
+