* expression.cs (IndexerAccess.ResolveAccessor): Add CS1540 check.
authorRaja R Harinath <harinath@hurrynot.org>
Tue, 2 Mar 2010 17:24:41 +0000 (17:24 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Tue, 2 Mar 2010 17:24:41 +0000 (17:24 -0000)
Diagnose code that caused the verification failure of System.ServiceModel.Routing.dll

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

mcs/errors/cs1540-11.cs [new file with mode: 0644]
mcs/mcs/ChangeLog
mcs/mcs/expression.cs

diff --git a/mcs/errors/cs1540-11.cs b/mcs/errors/cs1540-11.cs
new file mode 100644 (file)
index 0000000..1443179
--- /dev/null
@@ -0,0 +1,16 @@
+// CS1540: Cannot access protected member `A.this[int]' via a qualifier of type `B'. The qualifier must be of type `C' or derived from it
+// Line: 14
+
+class A {
+       protected int this [int i] { get { return i; } }
+}
+
+class B : A { }
+
+class C : A {
+       static int Main ()
+       {
+               B b = new B ();
+               return b [0];
+       }
+}
index a5a0011f5d3c9d996d29bcf1e68cc1dce99b4c63..0e3e85acaabaea018cfb054c69c4d8db91b390fb 100644 (file)
@@ -1,3 +1,7 @@
+2010-03-02  Raja R Harinath  <harinath@hurrynot.org>
+
+       * expression.cs (IndexerAccess.ResolveAccessor): Add CS1540 check.
+
 2010-03-02  Marek Safar  <marek.safar@gmail.com>
 
        * cs-tokenizer.cs: Missed few locations in previous fix.
index 06c2234f2ca75b4efa18f968f9d1a076e73c8d5f..84980efd5f599e287b40d3b870acd2b1e9f83c56 100644 (file)
@@ -8643,6 +8643,16 @@ namespace Mono.CSharp {
                        }
 
                        instance_expr.CheckMarshalByRefAccess (ec);
+
+                       if (must_do_cs1540_check && (instance_expr != EmptyExpression.Null) &&
+                           !TypeManager.IsInstantiationOfSameGenericType (instance_expr.Type, ec.CurrentType) &&
+                           !TypeManager.IsNestedChildOf (ec.CurrentType, instance_expr.Type) &&
+                           !TypeManager.IsSubclassOf (instance_expr.Type, ec.CurrentType)) {
+                               ec.Report.SymbolRelatedToPreviousError (accessor.MetaInfo);
+                               Error_CannotAccessProtected (ec, loc, accessor.MetaInfo, instance_expr.Type, ec.CurrentType);
+                               return null;
+                       }
+
                        eclass = ExprClass.IndexerAccess;
                        return this;
                }