[Mono-bugs] [Bug 78695][Nor] New - Inline delegate definition gets wrong accessibility.

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Jun 23 22:08:49 EDT 2006


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 erroneousbollock at gmail.com.

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

--- shadow/78695	2006-06-23 22:08:49.000000000 -0400
+++ shadow/78695.tmp.8281	2006-06-23 22:08:49.000000000 -0400
@@ -0,0 +1,92 @@
+Bug#: 78695
+Product: Mono: Compilers
+Version: 1.1
+OS: GNU/Linux [Other]
+OS Details: Ubuntu Dapper
+Status: NEW   
+Resolution: 
+Severity: Unknown
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: erroneousBollock at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Inline delegate definition gets wrong accessibility.
+
+Description of Problem:
+
+When passing an inline delegate to some function expecting a delegate, an
+anonymous function is created by the compiler. It seems that the
+accessibility assigned to that anonymous function is 'public'.
+
+That behaviour (in certain circumstances) stops you from passing an
+inline-delegate to some function expecting a  private/protected object (to
+be used by the delegate).
+
+I'm not sure how Microsoft's C#2.0 compiler infers the accessibility in
+this case, but I have verified that this test case does work in VS.NET 2005.
+
+Steps to reproduce the problem:
+1. Compile the following with gmcs:
+--------------------------------------------------------------
+using System;
+using System.Collections.Generic;
+
+namespace Foo
+{
+ public class Bar
+ {
+   public    class PublicBaz    { public string id; }
+   protected class ProtectedBaz { public string id; }
+   private   class PrivateBaz   { public string id; }
+
+   private void Test()
+   {
+     string nice = "dave";
+     List<PublicBaz>    pub = new List<PublicBaz>();
+     List<ProtectedBaz> prt = new List<ProtectedBaz>();
+     List<PrivateBaz>   prv = new List<PrivateBaz>();
+
+     pub = pub.FindAll(delegate (PublicBaz b)    { return b.id == nice; });
+     prt = prt.FindAll(delegate (ProtectedBaz b) { return b.id == nice; });
+     prv = prv.FindAll(delegate (PrivateBaz b)   { return b.id == nice; });
+   }
+
+   public static void Main(string [] args)
+   {
+     (new Bar()).Test();
+   }
+ }
+}
+--------------------------------------------------------------
+
+Actual Results:
+
+When I compile the above code, I get the following errors:
+
+bugTest.cs(20,25): error CS0051: Inconsistent accessibility:
+parameter type `Foo.Bar.ProtectedBaz' is less accessible than method
+Foo.Bar.<#AnonymousMethod>1 (Foo.Bar.ProtectedBaz)'
+ bugTest.cs(21,25): error CS0051: Inconsistent accessibility:
+parameter type `Foo.Bar.PrivateBaz' is less accessible than method
+`Foo.Bar.<#AnonymousMethod>2(Foo.Bar.PrivateBaz)'
+
+Expected Results:
+
+Microsoft's C#2.0 compiler only gives the following warning:
+  "Field 'Foo.Bar.PrivateBaz.id' is never assigned to, and will always have
+the default value null"
+
+How often does this happen? 
+
+Trivially repeatable.
+
+Additional Information:
+
+I have mono version 1.1.13.6.
+
+------- Additional Comments From erroneousBollock at gmail.com  2006-06-23 22:08 -------
+*** Bug 78694 has been marked as a duplicate of this bug. ***


More information about the mono-bugs mailing list