Bug 321419 (MONO78695) - [ANONYMOUS METHODS] (FIXED) Inline delegate definition gets wrong accessibility.
Summary: [ANONYMOUS METHODS] (FIXED) Inline delegate definition gets wrong accessibility.
Status: RESOLVED FIXED
Alias: MONO78695
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.1
Hardware: Other Linux
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Martin Baulig
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-23 05:40 UTC by David Toso
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:01:58 UTC


---- Reported by erroneousBollock@gmail.com 2006-06-22 22:41:44 MST ----

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@gmail.com 2006-06-23 22:08:49 MST ----

*** https://bugzilla.novell.com/show_bug.cgi?id=MONO78694 has been marked as a duplicate of this bug. ***



---- Additional Comments From martin@ximian.com 2006-09-14 11:55:21 MST ----

Added a better test case as test-martin-30.cs.



---- Additional Comments From martin@ximian.com 2006-10-04 18:14:51 MST ----

Fixed in SVN.



---- Additional Comments From martin@ximian.com 2006-10-04 18:18:36 MST ----

Fixed in SVN.


Unknown bug field "cf_op_sys_details" encountered while moving bug
   <cf_op_sys_details>Ubuntu Dapper</cf_op_sys_details>