From 2507041096891e7d50d7f1307336d82e01880d64 Mon Sep 17 00:00:00 2001 From: Raja R Harinath Date: Tue, 2 Mar 2010 17:24:41 +0000 Subject: [PATCH] * expression.cs (IndexerAccess.ResolveAccessor): Add CS1540 check. Diagnose code that caused the verification failure of System.ServiceModel.Routing.dll svn path=/trunk/mcs/; revision=152858 --- mcs/errors/cs1540-11.cs | 16 ++++++++++++++++ mcs/mcs/ChangeLog | 4 ++++ mcs/mcs/expression.cs | 10 ++++++++++ 3 files changed, 30 insertions(+) create mode 100644 mcs/errors/cs1540-11.cs diff --git a/mcs/errors/cs1540-11.cs b/mcs/errors/cs1540-11.cs new file mode 100644 index 00000000000..1443179bd85 --- /dev/null +++ b/mcs/errors/cs1540-11.cs @@ -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]; + } +} diff --git a/mcs/mcs/ChangeLog b/mcs/mcs/ChangeLog index a5a0011f5d3..0e3e85acaab 100644 --- a/mcs/mcs/ChangeLog +++ b/mcs/mcs/ChangeLog @@ -1,3 +1,7 @@ +2010-03-02 Raja R Harinath + + * expression.cs (IndexerAccess.ResolveAccessor): Add CS1540 check. + 2010-03-02 Marek Safar * cs-tokenizer.cs: Missed few locations in previous fix. diff --git a/mcs/mcs/expression.cs b/mcs/mcs/expression.cs index 06c2234f2ca..84980efd5f5 100644 --- a/mcs/mcs/expression.cs +++ b/mcs/mcs/expression.cs @@ -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; } -- 2.25.1