Skip to content

Commit

Permalink
* expression.cs (IndexerAccess.ResolveAccessor): Add CS1540 check.
Browse files Browse the repository at this point in the history
Diagnose code that caused the verification failure of System.ServiceModel.Routing.dll

svn path=/trunk/mcs/; revision=152858
  • Loading branch information
harinath committed Mar 2, 2010
1 parent 8976976 commit 2507041
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mcs/errors/cs1540-11.cs
Original file line number Diff line number Diff line change
@@ -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];
}
}
4 changes: 4 additions & 0 deletions mcs/mcs/ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 10 additions & 0 deletions mcs/mcs/expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8643,6 +8643,16 @@ Expression ResolveAccessor (ResolveContext ec, Expression right_side)
}

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;
}
Expand Down

0 comments on commit 2507041

Please sign in to comment.