Fix #328490
authorRaja R Harinath <harinath@hurrynot.org>
Wed, 3 Oct 2007 13:22:09 +0000 (13:22 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Wed, 3 Oct 2007 13:22:09 +0000 (13:22 -0000)
* mcs/ecore.cs (SimpleName.DoSimpleNameResolve): Handle Property and
Event accessibility checks here.  Remove some bogus code that
accidently made GenericMethods work.
(PropertyExpr.IsAccessibleFrom, EventExpr.IsAccessibleFrom): New.
* tests/test-589.cs: Additional test for #328490.
* errors/cs0120-10.cs: New test based on #328490.

svn path=/trunk/mcs/; revision=86807

1  2 
mcs/errors/ChangeLog
mcs/errors/cs0120-10.cs
mcs/mcs/ChangeLog
mcs/mcs/ecore.cs
mcs/tests/ChangeLog
mcs/tests/known-issues-gmcs
mcs/tests/known-issues-mcs
mcs/tests/test-589.cs

index 2c0002a8507a4d756c192d461074cb91c95c08cc,2c0002a8507a4d756c192d461074cb91c95c08cc..6ab901f863c15d35edd18eaf4d17a8b7d7a5a5b5
@@@ -1,3 -1,3 +1,7 @@@
++2007-10-03  Raja R Harinath  <rharinath@novell.com>
++
++      * cs0120-10.cs: New test based on #328490.
++
  2007-08-24  Atsushi Enomoto  <atsushi@ximian.com>
  
        * cs1570-12.cs : new test (bug #82565).
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..bf442a9c540143f5ed6059a8d3e4fcde0f23e4a7
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,41 @@@
++// CS0120: `TestNamespace.TestClass.HelloWorld()': An object reference is required for the nonstatic field, method or property
++// Line: 31
++
++using System;
++using TestNamespace;
++
++namespace TestNamespace
++{
++      public class TestClass
++      {
++              public void HelloWorld ()
++              {
++              }
++      }
++}
++
++class SuperClass
++{
++      TestClass tc = null;
++
++      TestClass TestClass
++      {
++              get { return tc; }
++      }
++}
++
++class SubClass : SuperClass
++{
++      public SubClass ()
++      {
++              TestClass.HelloWorld ();
++      }
++}
++
++class App
++{
++      public static void Main ()
++      {
++              SubClass sc = new SubClass ();
++      }
++}
index ec4724d8ee9a20cff7f61556a7281e8507e352ac,ec4724d8ee9a20cff7f61556a7281e8507e352ac..fa366f75cfc04370424e5f9f18126d8a6d9856dc
@@@ -1,3 -1,3 +1,11 @@@
++2007-10-03  Raja R Harinath  <rharinath@novell.com>
++
++      Fix #328490
++      * ecore.cs (SimpleName.DoSimpleNameResolve): Handle Property and
++      Event accessibility checks here.  Remove some bogus code that
++      accidently made GenericMethods work.
++      (PropertyExpr.IsAccessibleFrom, EventExpr.IsAccessibleFrom): New.
++
  2007-09-25  Marek Safar  <marek.safar@gmail.com>
        
        * expression.cs (ArrayCreation): Fixed cloning of an implicit types.
index 99e94ba0bf31d26c03f3221e17598bb60bcef09f,99e94ba0bf31d26c03f3221e17598bb60bcef09f..3ab7eb98bbf40fc80e7c972fff176215c6053004
@@@ -2311,27 -2311,27 +2311,34 @@@ namespace Mono.CSharp 
                        // Stage 2: Lookup members 
                        //
  
--                      DeclSpace lookup_ds = ec.DeclContainer;
                        Type almost_matched_type = null;
                        ArrayList almost_matched = null;
--                      do {
++                      for (DeclSpace lookup_ds = ec.DeclContainer; lookup_ds != null; lookup_ds = lookup_ds.Parent) {
++                              // either RootDeclSpace or GenericMethod
                                if (lookup_ds.TypeBuilder == null)
--                                      break;
++                                      continue;
  
                                e = MemberLookup (ec.ContainerType, lookup_ds.TypeBuilder, Name, loc);
--                              if (e != null)
--                                      break;
++                              if (e != null) {
++                                      if (e is PropertyExpr) {
++                                              // since TypeManager.MemberLookup doesn't know if we're doing a lvalue access or not,
++                                              // it doesn't know which accessor to check permissions against
++                                              if (((PropertyExpr) e).IsAccessibleFrom (ec.ContainerType, right_side != null))
++                                                      break;
++                                      } else if (e is EventExpr) {
++                                              if (((EventExpr) e).IsAccessibleFrom (ec.ContainerType))
++                                                      break;
++                                      } else {
++                                              break;
++                                      }
++                                      e = null;
++                              }
  
                                if (almost_matched == null && almostMatchedMembers.Count > 0) {
                                        almost_matched_type = lookup_ds.TypeBuilder;
                                        almost_matched = (ArrayList) almostMatchedMembers.Clone ();
                                }
--
--                              lookup_ds =lookup_ds.Parent;
--                      } while (lookup_ds != null);
--
--                      if (e == null && ec.ContainerType != null)
--                              e = MemberLookup (ec.ContainerType, ec.ContainerType, Name, loc);
++                      }
  
                        if (e == null) {
                                if (almost_matched == null && almostMatchedMembers.Count > 0) {
                        Report.Error (1546, loc, "Property `{0}' is not supported by the C# language. Try to call the accessor method `{1}' directly",
                                Name, sig.ToString ());
                }
--              
++
++              public bool IsAccessibleFrom (Type invocation_type, bool lvalue)
++              {
++                      bool dummy;
++                      MethodInfo accessor = lvalue ? setter : getter;
++                      if (accessor == null && lvalue)
++                              accessor = getter;
++                      return accessor != null && IsAccessorAccessible (invocation_type, accessor, out dummy);
++              }
++
                override public Expression DoResolve (EmitContext ec)
                {
                        if (resolved)
                        return true;
                }
  
++              public bool IsAccessibleFrom (Type invocation_type)
++              {
++                      bool dummy;
++                      return IsAccessorAccessible (invocation_type, add_accessor, out dummy) &&
++                              IsAccessorAccessible (invocation_type, remove_accessor, out dummy);
++              }
++
                public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
                {
                        return DoResolve (ec);
index 2273b47e992eca8c6295833eb3ec9264ab218a4f,2273b47e992eca8c6295833eb3ec9264ab218a4f..c57a7be0cffd62363e156c8eaa7b11d622aae402
@@@ -1,3 -1,3 +1,7 @@@
++2007-10-03  Raja R Harinath  <rharinath@novell.com>
++
++      * test-589.cs: Additional test for #328490.
++
  2007-09-26  Gert Driesen  <drieseng@users.sourceforge.net>
  
        * test-587.cs: test for bug #328136.
index f1a6480f88653376bcd7dd18eb102e07027e4135,f1a6480f88653376bcd7dd18eb102e07027e4135..48ea432d53d871d6be6b36b50665b59d2e0603b4
@@@ -11,8 -11,8 +11,10 @@@ test-539.cs IGNORE   # In 2.0 profile, Ru
  test-562.cs
  test-586.cs
  test-587.cs
--test-588.cs
  
++gtest-203.cs
++gtest-204.cs
  gtest-230.cs
++gtest-anon-12.cs
  
  ltest-11.cs
index 17b3fe3f11ed058d369a5d2088fba9a4abac11a9,17b3fe3f11ed058d369a5d2088fba9a4abac11a9..59128466e6460ee208e7bde6ed93a2f941704927
@@@ -11,4 -11,4 +11,3 @@@ test-xml-027.c
  test-562.cs
  test-586.cs
  test-587.cs
--test-588.cs
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..ccf81c7c6f92c6cbece5fcfe5fb3b5cd137cefc5
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,39 @@@
++using System;
++using TestNamespace;
++
++namespace TestNamespace
++{
++      public class TestClass
++      {
++              public static void HelloWorld ()
++              {
++              }
++      }
++}
++
++class SuperClass
++{
++      TestClass tc = null;
++
++      public TestClass TestClass
++      {
++              private get { return tc; }
++              set {}
++      }
++}
++
++class SubClass : SuperClass
++{
++      public SubClass ()
++      {
++              TestClass.HelloWorld ();
++      }
++}
++
++class App
++{
++      public static void Main ()
++      {
++              SubClass sc = new SubClass ();
++      }
++}