[Mono-devel-list] [RFA] Patch for #56300
Martin Baulig
martin at ximian.com
Wed Apr 28 12:48:14 EDT 2004
On Fri, 2004-04-16 at 00:20, Raja R Harinath wrote:
> Hi,
>
> I've attached a patch for #56300.
Looks good. Please commit.
>
> OK to apply?
>
> - Hari
>
>
> ______________________________________________________________________
> // Bug #56300
>
> using System;
> using System.Collections;
>
> namespace Test
> {
> public interface IIndexer { object this[int index] { get; set; } }
>
> public class Test : IIndexer
> {
> object[] InnerList;
> object IIndexer.this[int index] {
> get { return InnerList[index]; }
> set { InnerList[index] = value; }
> }
>
> public static void Main() {
> foreach (Attribute a in typeof(Test).GetCustomAttributes(false))
> if (a is System.Reflection.DefaultMemberAttribute)
> throw new Exception("Class 'Test' has a DefaultMemberAttribute");
> }
> }
> }
>
> ______________________________________________________________________
> mcs/class.cs | 36 ++++++++++++++++++------------------
> tests/Makefile | 2 +-
> tests/README.tests | 8 +++++++-
> 3 files changed, 26 insertions(+), 20 deletions(-)
>
> Index: mcs/ChangeLog
> from Raja R Harinath <rharinath at novell.com>
>
> * class.cs (TypeContainer.AddIndexer): Use
> 'ExplicitInterfaceName' to determine if interface name was
> explicitly specified. 'InterfaceType' is not initialized at this time.
> (TypeContainer.DefineIndexers): Remove use of temporary list. The
> Indexers array is already in the required order. Initialize
> 'IndexerName' only if there are normal indexers.
> (TypeContainer.DoDefineMembers): Don't initialize IndexerName.
> (TypeContainer.Emit): Emit DefaultMember attribute only if
> IndexerName is initialized.
> Fixes #56300.
>
> Index: mcs/class.cs
> ===================================================================
> RCS file: /cvs/public/mcs/mcs/class.cs,v
> retrieving revision 1.420
> diff -u -r1.420 class.cs
> --- mcs/class.cs 10 Apr 2004 18:56:55 -0000 1.420
> +++ mcs/class.cs 16 Apr 2004 03:13:11 -0000
> @@ -398,7 +398,7 @@
> if (indexers == null)
> indexers = new ArrayList ();
>
> - if (i.InterfaceType != null)
> + if (i.ExplicitInterfaceName != null)
> indexers.Insert (0, i);
> else
> indexers.Add (i);
> @@ -968,11 +968,11 @@
>
> //
> // Defines the indexers, and also verifies that the IndexerNameAttribute in the
> - // class is consisten. Either it is `Item' or it is the name defined by all the
> + // class is consistent. Either it is `Item' or it is the name defined by all the
> // indexers with the `IndexerName' attribute.
> //
> // Turns out that the IndexerNameAttribute is applied to each indexer,
> - // but it is never emitted, instead a DefaultName attribute is attached
> + // but it is never emitted, instead a DefaultMember attribute is attached
> // to the class.
> //
> void DefineIndexers ()
> @@ -984,17 +984,17 @@
> // explicit one actually implements the interface while the other one is just
> // a normal indexer. See bug #37714.
> //
> - ArrayList list = new ArrayList ();
> - foreach (Indexer i in Indexers){
> - if (i.ExplicitInterfaceName != null)
> - list.Add (i);
> - }
> - foreach (Indexer i in Indexers){
> +
> + // Invariant maintained by AddIndexer(): All explicit interface indexers precede normal indexers
> + bool seen_normal_indexers = false;
> + foreach (Indexer i in Indexers) {
> if (i.ExplicitInterfaceName == null)
> - list.Add (i);
> + seen_normal_indexers = true;
> + else if (seen_normal_indexers)
> + throw new Exception ("Internal Error: 'Indexers' array not sorted properly.");
> }
>
> - foreach (Indexer i in list){
> + foreach (Indexer i in Indexers) {
> string name;
>
> i.Define (this);
> @@ -1016,7 +1016,8 @@
> 668, "Two indexers have different names, " +
> " you should use the same name for all your indexers");
> }
> - if (class_indexer_name == null)
> +
> + if (seen_normal_indexers && class_indexer_name == null)
> class_indexer_name = "Item";
> IndexerName = class_indexer_name;
> }
> @@ -1152,10 +1153,8 @@
> if (events != null)
> DefineMembers (events, defined_names);
>
> - if (indexers != null) {
> + if (indexers != null)
> DefineIndexers ();
> - } else
> - IndexerName = "Item";
>
> if (operators != null){
> DefineMembers (operators, null);
> @@ -1764,9 +1763,10 @@
> if (indexers != null){
> foreach (Indexer ix in indexers)
> ix.Emit (this);
> -
> - CustomAttributeBuilder cb = EmitDefaultMemberAttr ();
> - TypeBuilder.SetCustomAttribute (cb);
> + if (IndexerName != null) {
> + CustomAttributeBuilder cb = EmitDefaultMemberAttr ();
> + TypeBuilder.SetCustomAttribute (cb);
> + }
> }
>
> if (fields != null)
> Index: tests/ChangeLog
> from Raja R Harinath <rharinath at novell.com>
>
> * test-236.cs: Test for #56300.
>
> Index: tests/Makefile
> ===================================================================
> RCS file: /cvs/public/mcs/tests/Makefile,v
> retrieving revision 1.51
> diff -u -r1.51 Makefile
> --- tests/Makefile 29 Mar 2004 21:40:49 -0000 1.51
> +++ tests/Makefile 16 Apr 2004 03:13:11 -0000
> @@ -39,7 +39,7 @@
> test-201 test-202 test-203 test-204 test-205 test-206 test-207 test-208 test-209 test-210 \
> test-211 test-212 test-213 test-214 test-215 test-216 test-217 test-218 test-219 test-220 \
> test-221 test-222 test-223 test-224 test-225 test-226 test-227 test-229 test-230 \
> - test-231 test-232 test-233 test-234 test-235 \
> + test-231 test-232 test-233 test-234 test-235 test-236 \
> cls-test-0 cls-test-1 cls-test-2 cls-test-3 cls-test-5 cls-test-6 cls-test-7 cls-test-10 \
> cls-test-11 cls-test-14 cls-test-15 cls-test-16
>
> Index: tests/README.tests
> ===================================================================
> RCS file: /cvs/public/mcs/tests/README.tests,v
> retrieving revision 1.81
> diff -u -r1.81 README.tests
> --- tests/README.tests 22 Mar 2004 04:52:05 -0000 1.81
> +++ tests/README.tests 16 Apr 2004 03:13:11 -0000
> @@ -15,7 +15,8 @@
>
> * Indexers and Properties
>
> - test-148.cs test-166.cs test-206.cs test-208.cs test-209.cs test-221.cs
> + test-148.cs test-166.cs test-206.cs test-208.cs test-209.cs
> + test-221.cs test-236.cs
>
> * Events and Delegates
>
> @@ -460,6 +461,11 @@
> test-234.cs:
> ------------
> Switch statement on a [Flags] style enum. bug 55885.
> +
> +test-236.cs:
> +-----------
> +Test for bug #56300. DefaultMemberAttribute should not be created if a
> +class has only private interface indexers.
>
> verify-1.cs
> -----------
--
--
Martin Baulig <martin at ximian.com>
Now blogging ! http://primates.ximian.com/~martin/blog
More information about the Mono-devel-list
mailing list